在Xcode Obj C中使用body发送HTTP GET请求

时间:2017-04-24 10:36:31

标签: objective-c xcode http get

我正在开发一个应用程序,我需要在其中发送带有自定义正文内容的HTTP GET请求,就像POST请求一样。 当我刚从POST将HTTP方法更改为GET时,我收到以下错误。

nw_endpoint_flow_service_writes [9 server.url ready socket-flow (satisfied)] Write request has 4294967295 frame count, 0 byte count
tcp_connection_write_eof_block_invoke Write close callback received error: [89] Operation canceled

按如下方式形成请求,

NSMutableURLRequest *urlRequest = [NSMutableURLRequest 
requestWithURL:[NSURL URLWithString:domainName] 
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
 NSData *postData = [NSJSONSerialization dataWithJSONObject:requestData options:0 error:nil];
[urlRequest addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[urlRequest setHTTPMethod:@"GET"];
[urlRequest setHTTPBody:postData];

在服务器中,我收到以下GET请求错误消息,

Error: request aborted
at IncomingMessage.onAborted (/node_modules/raw-body/index.js:269:10)
at emitNone (events.js:80:13)
at IncomingMessage.emit (events.js:179:7)
at abortIncoming (_http_server.js:280:11)
at Socket.serverSocketCloseListener (_http_server.js:293:5)
at emitOne (events.js:95:20)
at Socket.emit (events.js:182:7)
at TCP._onclose (net.js:475:12)

如果我在发送请求时出错,请纠正我。

0 个答案:

没有答案