发送请求iOS,响应状态码:500

时间:2016-08-09 13:07:40

标签: ios objective-c request odata

您好我将json数据发送到odata服务器,但我在响应中获得状态代码500。因此500被描述为服务器故障我确信服务器工作正常。我google了很多,我仍然无法弄清楚出了什么问题......这是我的代码:

NSMutableURLRequest *request2 = [NSMutableURLRequest requestWithURL:url];
     //I found thet some people had troubles due to their url had some spetial characters inside, however this is not my case

     //Create POST Params and add it to HTTPBody
     [request2 setHTTPMethod:@"POST"];
     [request2 setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
     [request2 setValue:@"application/json" forHTTPHeaderField:@"Accept"];
     [request2 setHTTPBody:jsonData];

     //authorization
     NSString *authStr2 = @"username:password";
     NSData *authData2 = [authStr2 dataUsingEncoding:NSUTF8StringEncoding];
     NSString *authValue2 = [NSString stringWithFormat: @"Basic %@",[authData2 base64EncodedStringWithOptions:0]];
     [request2 setValue:authValue2 forHTTPHeaderField:@"Authorization"];

     //Create task
     NSURLSessionDataTask *dataTask = [defaultSession dataTaskWithRequest:request2 completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
     NSLog(@"Response:%@ %@\n", response, error);
     if(error){
     NSLog(@"ERROR---0");
     }
     }];[dataTask resume];

我很高兴知道我哪里可以搞砸了,非常感谢!

0 个答案:

没有答案