我尝试使用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];
我只是在尝试为什么我会得到错误以及正确的方法。
由于
答案 0 :(得分:1)
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];