を送りたいJSON file from my WP7 device to my local server
です。iOSではASIHttpRequest
ライブラリを使用しましたが、私がしたことは次のとおりです。
//send json file , using ASIHttpClass
NSURL *url = [NSURL URLWithString:urlStr];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
request.timeOutSeconds = TIME_OUT_SECONDS;
[request setRequestMethod:@"PUT"];
NSString *credentials= [self encodeCredentials];
[request addRequestHeader:@"Authorization" value:[[NSString alloc] initWithFormat:@"Basic %@",credentials]];
[request addRequestHeader:@"Content-Type" value:@"application/json; charset=utf-8"];
[request appendPostData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
[request startSynchronous];
if([request responseStatusCode]==200){
return true;
} else {
return false;
}
WP7 アプリケーションで同じ機能を実装するにはどうすればよいですか?
私が今まで見つけたものと私は近いと思います:
//Making a POST request using WebClient.
Function()
{
WebClient wc = new WebClient();
var URI = new Uri("http://your_uri_goes_here");
wc.Headers["Authorization"] = "Basic (here goes my credentials string which i have)";
wc.Headers["Content-Type"] = "application/json; charset=utf-8";
wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted);
wc_cart_session.UploadStringAsync(URI,"POST","Data_To_Be_sent");
}
どこ :
void wc__UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
{
try
{
MessageBox.Show(e.Result);
//e.result fetches you the response against your POST request.
}
catch(Exception exc)
{
MessageBox.Show(exc.ToString());
}
}
「Data_to_be_Sent」は、utf8エンコーディングのjsonStringである必要があると思いますか?
編集
が文字列であることに気付きました"Data_To_Be_sent"
。ただし、これは UTF8 エンコーディングである必要があります。したがって、UTF8 形式のバイト配列である必要があります。ただし、そこに文字列しか配置できません。ここで何が欠けていますか?