0

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

 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];

我只是在尝试为什么我会收到该错误以及正确执行此操作的方法。

谢谢

4

1 回答 1

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];
于 2013-02-24T03:31:09.177 回答