簡體   English   中英

發送HTTP POST請求不起作用

[英]Sending HTTP POST Request not working

不知道出什么問題了:

//Send distance to ThingSpeak Server
NSString *distanceString = [NSString stringWithFormat:@"%1.6f", currentDistance];
NSString *post = [NSString stringWithFormat:@"api_key=H3MQFPAJ1IOK1WEI0W&field1=%@", distanceString];

NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"https://api.thingspeak.com/update"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

我只是想將數據發送到ThingSpeak服務器,但是Xcode在運行時始終向我拋出錯誤。 我是Xcode的新手,所以我不確定如何讀取錯誤。 它只是在我的控制台中說(lldb),並給了我一個“ Thread1,斷點1.1”:

在此處輸入圖片說明

謝謝

我添加了這段代碼,它的工作原理是:

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[conn start];

另外,斷點問題是由於我在單擊時不小心添加了一個斷點而出現的,它看起來像一個藍色標簽。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM