2013-06-20 26 views
0

当我使用带有xml值的参数格式调用雅虎用户配置文件API时,雅虎正在发送JSONP(JSONP覆盖括号(<JSON>);)结果,但是当我通过发送此请求时Google chrome的邮递员插件Yahoo api正在发送XML结果。雅虎配置文件API通过RestSharp发送JSONP结果

API是:

http://social.yahooapis.com/v1/user/ {GUID}/profile文件

文件:http://developer.yahoo.com/social/rest_api_guide/extended-profile-resource.html

我的代码

public string RestApiInvoke(string url, TRANSPORT_METHOD method, Dictionary<string, string> data, Dictionary<string, string> headers) 
     { 
      var client = new RestClient(url); 
      RestRequest request; 

      if (method == TRANSPORT_METHOD.POST) 
      { 
       request = new RestRequest(Method.POST); 
      } 
      else 
      { 
       request = new RestRequest(Method.GET); 
      } 

      if (data.IsNotNullOrEmpty()) 
      { 
       foreach (var item in data) 
       { 
        request.AddParameter(item.Key, item.Value); 
       } 
      } 

      if (headers.IsNotNullOrEmpty()) 
      { 
       foreach (var item in headers) 
       { 
        request.AddHeader(item.Key, item.Value); 
       } 
      } 

      IRestResponse response = client.Execute(request); 

      return response.Content; 
     } 

回答

0

我得到了答案,仅有Accepttext/xml,其实RestSharp使用接受类似application/json text/html text/xml的东西,所以雅虎挑选第一个并发送JSONP结果。我使用下面的代码手动设置它。

headers.Add("Accept", "text/xml");