Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将json post从xcode发送到wep.api_Json_Xcode4.6 - Fatal编程技术网

将json post从xcode发送到wep.api

将json post从xcode发送到wep.api,json,xcode4.6,Json,Xcode4.6,向Wep.api应用程序发送post消息时遇到问题。我已经在google chrome postman应用程序上试用了我的wep.api,它运行得非常好。我希望xcode中的代码将此json消息发送到我的wep.api Content-Type: application/json; charset=utf-8 { UserName: "fjkdlajfka", DeviceID: "1568948" , Password: "fkjdalfda"} 但每次我发送消息时,参数总是为空。这是我的x

向Wep.api应用程序发送post消息时遇到问题。我已经在google chrome postman应用程序上试用了我的wep.api,它运行得非常好。我希望xcode中的代码将此json消息发送到我的wep.api

Content-Type: application/json; charset=utf-8
{ UserName: "fjkdlajfka", DeviceID: "1568948" , Password: "fkjdalfda"}
但每次我发送消息时,参数总是为空。这是我的xcode消息:

NSString *JsonMsg = [NSString stringWithFormat:@"{UserName: \"%@\",DeviceID: \"%@\",Password: \"%@\"}",
                     Username.text,@"123456789",Password.text];
NSURL *url = [NSURL URLWithString: @"http://192.168.xxx.xxxx:53913/api/LogIn"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [JsonMsg length]];

[theRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[theRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[theRequest setValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[JsonMsg dataUsingEncoding:NSUTF16BigEndianStringEncoding allowLossyConversion:YES]];

conn = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

if ( conn ) {
    webData = [NSMutableData data];

}
else {
    NSLog(@"theConnection is NULL");
}

有人知道这里的错误是什么吗?

您的JSON无效,缺少引号

NSString *JsonMsg = [NSString stringWithFormat:@"{"UserName": \"%@\",
                                                  "DeviceID": \"%@\",
                                                  "Password": \"%@\"}",
                     Username.text,@"123456789",Password.text];