ASIHTTPRequest with Put问题& kCFErrorDomainCFNetwork错误303

时间:2013-02-23 20:20:13

标签: ios asihttprequest

我尝试使用ASIHTTPRequest将文件从Document文件夹上传到URL      放方法。我收到以下错误,似乎是kCFErrorHTTPParseFailure错误。任何想法是什么问题以及如何解决?

 Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred"
 UserInfo=0xe027890 {NSUnderlyingError=0xe026300 "The operation couldn’t be completed. 
(kCFErrorDomainCFNetwork error 303.)", NSLocalizedDescription=A connection failure 
 occurred}

 My code as follow 

NSURL *url = [NSURL URLWithString:@"http://www.uploadURL/"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setRequestMethod:@"PUT"];
[request addBasicAuthenticationHeaderWithUsername:@"UsrName"
                                      andPassword:@"UserPassword"];
[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
 request.shouldAttemptPersistentConnection   = NO;

[request setPostBodyFilePath:fullPathFile];
[request setShouldStreamPostDataFromDisk:YES];
[request startAsynchronous];

我只是在尝试为什么我会得到错误以及正确的方法。

由于

1 个答案:

答案 0 :(得分:1)

好吧,我确实搞清楚了。以下代码用于使用HTTP put来上载文件。希望能帮助别人。

 NSURL *url = [NSURL URLWithString:@"http://www.SomeSite/UploadFolder/FileName.ext"];
 ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
 [request setRequestMethod:@"PUT"];
 [request addBasicAuthenticationHeaderWithUsername:@"UsrName"
                                       andPassword:@"UsrPassword"];
 [request setShouldPresentCredentialsBeforeChallenge:YES];
 [request setDelegate:self];
 [request setAuthenticationScheme:(NSString *) kCFHTTPAuthenticationSchemeBasic];

 [request setPostBodyFilePath:fullFilePath]; // Example: Documents/MyFile.txt
 [request setShouldStreamPostDataFromDisk:YES];
 [request startAsynchronous];