您的連接數據使用特殊字符,如果您嘗試使用NSURLConnection的GET方法執行此操作。它會顯示連接錯誤。爲此,您必須使用POST方法,如:
NSData *body = nil;
NSString *contentType = @"text/html; charset=utf-8";
NSURL *finalURL = @"YOUR URL WITH the ?input=";
NSString *yourString = @"geoX#35#geoY#65";
contentType = @"application/x-www-form-urlencoded; charset=utf-8";
body = [[NSString stringWithFormat:@"%@", yourString] dataUsingEncoding:NSUTF8StringEncoding];
if (nil==finalURL) {
finalURL = url;
}
NSMutableDictionary* headers = [[[NSMutableDictionary alloc] init] autorelease];
[headers setValue:contentType forKey:@"Content-Type"];
[headers setValue:mimeType forKey:@"Accept"];
[headers setValue:@"no-cache" forKey:@"Cache-Control"];
[headers setValue:@"no-cache" forKey:@"Pragma"];
[headers setValue:@"close" forKey:@"Connection"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:finalURL
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:body];
self.conn = [NSURLConnection connectionWithRequest:request delegate:self];
非常感謝!一個問題在哪裏定義url和mimeType?有點困惑這兩個。關於這個事實,我添加我的URL在finalURL定義。 –
好吧,我發現如何申報這兩個。我用@「mimeType」更改了mimeType,並且我設法建立了連接。壞消息是我得到了415錯誤,這意味着輸入無法識別。任何想法?:) 在此先感謝 –