Hi i want to send a post request to a server with api_key and version In curl i am able to send via the command
curl -X POST -F "[email protected]" "https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classify?api_key=fc1isndcb9fb837d139b11644ksks8cf3d66e175&version=2016-05-20"
When i try to do it in Objective C using the code
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:@"POST"];
[request setURL:[NSURL URLWithString:URL]];
[request addValue:@"fc1isndcb9fb837d139b11644ksks8cf3d66e175" forHTTPHeaderField:@"api_key"];
[request addValue:@"2016-05-20" forHTTPHeaderField:@"version"];
[request setHTTPBody:strData];
NSError *error = nil;
NSHTTPURLResponse *responseCode = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&responseCode error:&error];
It shows api_key is invalid. Am i doing anything wrong?
In your
curlexample, theapi_keyandversionare put in the url path. In your objc example code, you put them in theheaderfield, they are not the same.To achieve the same result, you should merge the two parameters into the
NSURLentity.