HttpWebRequest 请求 = (HttpWebRequest) HttpWebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
从 Yahoo 返回 POST 数据(我使用 Fiddler 检查):
{"error":{"code":-1003,"detail":"不支持的内容类型错误","description":"不支持的内容类型错误"},"code":-1003}
我正在编写需要application/json 的 Yahoo Messanger 客户端;charset=utf-8作为内容类型,当我设置时:
request.ContentType = "应用程序/json; charset=utf-8";
没有 POST 数据发送,从 Yahoo 返回:
{"error":{"code":-1005,"detail":"无效参数错误","description":"无效参数错误"},"code":-1005}
更新
我试图通过 POST 方法发送这 2 个值:presenceState & status。
如Yahoo Messager IM API中所述,支持的内容类型为application/json。在我的代码中,如果我将content-type设置为application/json,则HttpWebRequest不会通过 POST 发送这两个值。