我正在尝试使用ASIHTTPRequest put方法将文件从文档文件夹上传到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];
我只是在尝试为什么我得到了那个错误和正确的方法。
谢谢
发布于 2013-02-24 11:31:09
好吧,我确实想通了。以下代码用于使用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];
https://stackoverflow.com/questions/15045191
复制相似问题