本文介绍了如何在iOS中发送获取请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个库,以便从指定的数据和方法类型的特定URL获取响应。为此,我使用url进行请求。但是,当我设置它的方法类型时,它显示了无法识别的选择器发送的异常 [NSURLRequest setHTTPMethod:]
我将它设置为

I am making a library to get response from a particular URL with specified data and method type. For this, I am making a request with url. But when I set its method type, it shows an exception of unrecognized selector send in [NSURLRequest setHTTPMethod:]I am setting it as

[requestObject setHTTPMethod:@"GET"];

告诉我可能是什么问题。

Tell me what could be the problem. Also provide me the code if you have.

推荐答案

NSMutableURLRequest *request =
[NSMutableURLRequest requestWithURL:[NSURL
            URLWithString:serverAddress]
            cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                                                   timeoutInterval:10
 ];

[request setHTTPMethod: @"GET"];

NSError *requestError = nil;
NSURLResponse *urlResponse = nil;


NSData *response1 =
        [NSURLConnection sendSynchronousRequest:request
                         returningResponse:&urlResponse error:&requestError];

这篇关于如何在iOS中发送获取请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 20:56
查看更多