检查sendsynchronousrequest是否成功

发布于 2024-09-18 22:51:50 字数 304 浏览 7 评论 0原文

我只是想知道这是否是检查 sendsynchronousrequest 是否成功的正确方法:

NSData* returnData = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:nil];
if(returnData == nil)
{
    //code showing an alertView for example
}
else
{
    //do somthing else
}

提前感谢您的反馈
肖恩

i just wanted to know if this is the right way to check if a sendsynchronousrequest was successful:

NSData* returnData = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:nil];
if(returnData == nil)
{
    //code showing an alertView for example
}
else
{
    //do somthing else
}

thanks in advance for your feedback
sean

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

装纯掩盖桑 2024-09-25 22:51:50

我想你想为你的错误传递一些东西:

NSData* returnData = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:&error];

if(error != 0)
  // good to go
else
  // error

但我可能是错的,只是快速浏览了一下。

我确实看到了这篇文章..我认为他在问类似的事情:

http:// Discuss.apple.com/thread.jspa?threadID=1647649

I think you want to pass something in for your error:

NSData* returnData = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:&error];

if(error != 0)
  // good to go
else
  // error

But I could be wrong, just quickly glanced at it.

I did see this post though.. I think he's asking a similar thing:

http://discussions.apple.com/thread.jspa?threadID=1647649

jJeQQOZ5 2024-09-25 22:51:50

如果您使用 HTTP,那么您还可以检查状态代码。例如:

NSHTTPURLResponse *response;
NSError *error;
NSData *data = [NSURLConnection sendSynchronousRequest:request
                                     returningResponse:&response
                                                 error:&error];

if ((nil != data) && (200 == [response statusCode])) {
    // Process data
}

If you're working with HTTP, then you might also check the status code. For example:

NSHTTPURLResponse *response;
NSError *error;
NSData *data = [NSURLConnection sendSynchronousRequest:request
                                     returningResponse:&response
                                                 error:&error];

if ((nil != data) && (200 == [response statusCode])) {
    // Process data
}
寒江雪… 2024-09-25 22:51:50

正确的方法是定义一个错误变量,将其设置为 nil 并在 nsurlconnection 中使用其引用,以便在该引用内存位置返回错误。检查内存是否为 nil,如果 nil 成功,如果有一些有效内存,则为错误

NSError *error;
NSData *data = [NSURLConnection sendSynchronousRequest:request
                                     returningResponse:&response
                                                 error:&error];

if (error ==nil ) {
    // Success mechanism
}
else
{
 //Failure Mechanism
}

The correct way is to define an error variable set it nil and use its reference in nsurlconnection such that the error is returned in that reference memory position .Check the memory is nil and if nil success,if it has some valid memory it is error

NSError *error;
NSData *data = [NSURLConnection sendSynchronousRequest:request
                                     returningResponse:&response
                                                 error:&error];

if (error ==nil ) {
    // Success mechanism
}
else
{
 //Failure Mechanism
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文