Custom Header in ASIHTTPREQUEST

Posted by Sharon Nathaniel on Stack Overflow See other posts from Stack Overflow or by Sharon Nathaniel
Published on 2012-06-06T04:37:34Z Indexed on 2012/06/06 4:40 UTC
Read the original article Hit count: 205

Filed under:
|
|

Here is my problem. I am using ASIHTTPREQUEST to send request and get response. Now my need of the time is to upload a image,audio , video or docs via PUT method with a custom header . The header takes filename , filesize,sha256sum,username,mediatype,resume as parameters. Here is the code how I am doing that .

-(void)uploadFile
{
   NSString *resume =@"0";
    NSUserDefaults *userCredentials =[NSUserDefaults standardUserDefaults];
    NSString *userName =[userCredentials objectForKey:@"userName"];
    NSArray *objects =[NSArray arrayWithObjects:selectedMediaType,delegate.fileName,userName,fileSize,fileSHA256Sum,resume, nil];
    NSArray *keys =[NSArray arrayWithObjects:@"mediatype",@"file_name",@"usrname",@"filesize",@"sha256sum",@"resume", nil];
    discSentValue =[NSDictionary dictionaryWithObjects:objects forKeys:keys];
    NSURL *url = [NSURL URLWithString:@"http://briareos.code20.com/putmedia.php"];
    uploadMedia = [ASIFormDataRequest requestWithURL:url];
    [uploadMedia addRequestHeader:@"MEDIA_UPLOAD_CUSTOM_HEADER" value:[discSentValue JSONRepresentation]];
    [uploadMedia setData:dataToUpload forKey:@"File"];
    [uploadMedia setDelegate:self];
    [uploadMedia setRequestMethod:@"PUT"];
    [uploadMedia startAsynchronous];
}

But the server is unable to recognize the header , it always returns

"invalid header"

© Stack Overflow or respective owner

Related posts about iphone

Related posts about ios