这是我向服务器发送命令的方法:
- (void)sendCommand:(NSString *)command
{
NSURL *phpURL=[NSURL URLWithString:[DTAPI_Host stringByAppendingString:DTAPI_Path]];
NSMutableURLRequest *phpRequest=[[NSMutableURLRequest alloc] initWithURL:phpURL];
[phpRequest setHTTPMethod:@"POST"];
[phpRequest setValue:@"Accept" forHTTPHeaderField:@"application/json"];
[phpRequest setValue:[NSString stringWithFormat:@"%d", command.length] forHTTPHeaderField:@"Content-length"];
phpRequest.HTTPBody = [command dataUsingEncoding:NSUTF8StringEncoding];
[NSURLConnection connectionWithRequest:phpRequest delegate:self];
}
在里面:- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
我得到:Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost."
最令人困惑的部分是当我在我的 Mac 上使用 Safari 发送相同的请求时,它可以正常工作。
我错过了什么?