Can';t将响应头设置为application/json

Can';t将响应头设置为application/json,json,rest,Json,Rest,我的请求的头是application/json,但我的响应的头是application/xml。如何将响应头更改为application/json 请求标头: 响应标题: 守则: ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://wcftest.amerikanhastanesi.org/BarkodIOS.svc/rest/HastaAra"]]; NSD

我的请求的头是application/json,但我的响应的头是application/xml。如何将响应头更改为application/json

请求标头:

响应标题:

守则:

    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://wcftest.amerikanhastanesi.org/BarkodIOS.svc/rest/HastaAra"]];
    NSData *myPostData = [[NSString stringWithFormat:@"{\"protokolNo\":%d}",protokolNo] dataUsingEncoding:NSUTF8StringEncoding];
    NSMutableData *myMutablePostData = [[NSMutableData alloc]initWithData:myPostData];

    [request setPostBody:myMutablePostData];
    [request setRequestMethod:@"POST"];

    [request addRequestHeader:@"Content-Type" value:@"application/json"];
    [request setDelegate:self];
    [request startSynchronous];
    NSLog(@"%@",[request responseHeaders]);
    NSLog(@"%@",[request requestHeaders]);

     id jsonObjects = [NSJSONSerialization JSONObjectWithData:[[request responseString]
     dataUsingEncoding:NSUTF8StringEncoding]
     options:NSJSONReadingMutableContainers
     error:nil ];
    HastaModel *h;
    for(NSDictionary *theItem in [jsonObjects objectForKey:@"HastaAraResult"]){
        h = [[HastaModel alloc]initWithDictionary: theItem];

    }

    return h;

请不要要求我使用ASIFormData而不是ASIHTTPRequest。谢谢。

如果实现了真正的REST完整,您可以使用头参数:Accept:application/json

什么是响应?它与iOS或objective-c无关。web服务器必须将内容类型头添加到响应中。我修改了MIME,但不起作用。然后我将[WebInvoke(Method=“POST”,RequestFormat=WebMessageFormat.Json,ResponseFormat=WebMessageFormat.Json)]添加到cs中,但它也不起作用。因此,我认为这是代码问题。请编辑您的问题,以包含用于生成HTTP响应的代码(特别是该响应的标头)。响应标头由响应的服务器设置。如果您希望响应是json而不是xml,那么您需要确定如何更改请求,以便响应服务器发送json?我添加了[WebInvoke(Method=“POST”)、RequestFormat=WebMessageFormat.JSON、ResponseFormat=WebMessageFormat.JSON、UriTemplate=“sada”]我怎么能理解呢?我将rest端点添加到wcf。
"Cache-Control" = private;
Connection = close;
"Content-Length" = 689;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Mon, 09 Dec 2013 06:45:32 GMT";
Server = "Microsoft-IIS/7.5";
"X-AspNet-Version" = "4.0.30319";
"X-Powered-By" = "ASP.NET";
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://wcftest.amerikanhastanesi.org/BarkodIOS.svc/rest/HastaAra"]];
    NSData *myPostData = [[NSString stringWithFormat:@"{\"protokolNo\":%d}",protokolNo] dataUsingEncoding:NSUTF8StringEncoding];
    NSMutableData *myMutablePostData = [[NSMutableData alloc]initWithData:myPostData];

    [request setPostBody:myMutablePostData];
    [request setRequestMethod:@"POST"];

    [request addRequestHeader:@"Content-Type" value:@"application/json"];
    [request setDelegate:self];
    [request startSynchronous];
    NSLog(@"%@",[request responseHeaders]);
    NSLog(@"%@",[request requestHeaders]);

     id jsonObjects = [NSJSONSerialization JSONObjectWithData:[[request responseString]
     dataUsingEncoding:NSUTF8StringEncoding]
     options:NSJSONReadingMutableContainers
     error:nil ];
    HastaModel *h;
    for(NSDictionary *theItem in [jsonObjects objectForKey:@"HastaAraResult"]){
        h = [[HastaModel alloc]initWithDictionary: theItem];

    }

    return h;