0

我打电话给网络服务,我得到 0 个字节作为响应,并得到如下错误:

错误域=kCFErrorDomainCFNetwork 代码=303 “操作无法完成。(kCFErrorDomainCFNetwork 错误 303。)” UserInfo=0xa9b8ef0 {NSErrorFailingURLKey= http://quantuminfoways.com/crossfit_wodgenius/webservice/sync.php , NSErrorFailingURLStringKey= http:// /quantuminfoways.com/crossfit_wodgenius/webservice/sync.php }

我将数据作为 示例链接传递。

在数据中我传递了这个:

{
    createwod =     {
        deletedcreatewod =         (
        );
        newcreatewod =         (
        );
    };
    favorite =     {
        deletedfavorite =         (
        );
        newfavorite =         (
        );
    };
    gym =     {
        deletedgym =         (
        );
        newgym =         (
        );
    };
    workoutlog =     {
        deletedworkoutlog =         (
        );
        deletedworkoutlogtime =         (
        );
        newworkoutlog =         (
        );
    };
}

任何人都可以帮我解决它吗?

谢谢

4

2 回答 2

0

将 POST 方法作为 GET 调用时出现错误“kcferrordomaincfnetwork 错误 303”的原因之一。

于 2013-05-07T10:58:05.540 回答
-2

303 错误是重定向错误。

您可能想查看使用 NSURLConnection 自动处理重定向: https ://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/RequestChanges.html

如果您想手动处理它,重定向 url 位于响应的“位置”标头中。以下是在连接中获取它的方法:didReceiveResponse 委托方法。

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
    // ... if the response status is 303 ...
    if ([response respondsToSelector:@selector(allHeaderFields)]) {
        NSString* location = [[httpResponse allHeaderFields] valueForKey:@"Location"];
            // do whatever with the redirect url 
    }
}

您还可以尝试 urlEncoding 您的 url,包括数据。试试如果你只调用以下 URL 会发生什么:http: //quantuminfoways.com/crossfit_wodgenius/webservice/sync.php?udid=123&new=yes&uid=45&data=%20%7B%20createwod%20=%20 %7B%20deletedcreatewod %20=%20(%20);%20newcreatewod%20=%20(%20);%20%7D;%20favorite%20=%20%7B%20deletedfavorite%20=%20(%20);%20newfavorite %20=%20(%20);%20%7D;%20gym%20=%20%7B%20deletedgym%20=%20(%20);%20newgym%20=%20(%20);%20 %7D;%20workoutlog%20=%20%7B%20deletedworkoutlog%20=%20(%20);%20deletedworkoutlogtime%20=%20(%20);%20newworkoutlog%20=%20(%20);%20 %7D;%20%7D

于 2013-02-02T16:11:41.490 回答