I have created an endpoint to an entity and deployed to google cloud app engine.
我已经为实体创建了一个端点并部署到了谷歌云应用引擎。
https://alert-streamer-857.appspot.com/_ah/api/error/v1/error
If I POST the following JSON using Advanced REST Client in chrome, the item is successfully getting added to datastore.
如果我使用chrome中的Advanced REST Client发布以下JSON,则该项目已成功添加到数据存储区。
{
ipAddress: "123.456.789.098",
host: "jbuddha-lap",
user: "buddha",
message: "testing from c#"
}
I'm getting following response
我得到了以下回应
{
"id": "5642554087309312",
"syncTime": "2015-02-16T06:52:10.347Z",
"user": "buddha",
"host": "jbuddha-lap",
"ipAddress": "123.456.789.098",
"message": "testing from c#",
"kind": "error#resourcesItem",
"etag": "\"7D_54po0JQelJxcYULKayrO-_rE/GG6ep9m3yZRlAja6F1zqro8PO20\""
}
This is as expected. However the problem I'm facing is I'm trying to send the exact same json from a c# program, it is not getting added successfully. Following is the c# program that is sending this info.
这是预期的。然而,我面临的问题是我正在尝试从c#程序发送完全相同的json,它没有成功添加。以下是发送此信息的c#程序。
string json = "{ ipAddress: \"123.456.789.098\",host: \"jbuddha-lap\",user: \"buddha\",message: \"testing from c#\"}";
string result = "";
using (var client = new WebClient())
{
result = client.UploadString("https://alert-streamer-857.appspot.com/_ah/api/error/v1/error", "POST", json);
}
Console.WriteLine(result);
Following is the JSON response. The values for id and syncTime are autogenerated, that is the reason they appear in both the responses. But as you may have seen insertion is not happening correctly.
以下是JSON响应。 id和syncTime的值是自动生成的,这就是它们出现在两个响应中的原因。但是你可能已经看到插入没有正确发生。
{
"id": "5086441721823232",
"syncTime": "2015-02-16T06:57:28.249Z",
"kind": "error#resourcesItem",
"etag": "\"7D_54po0JQelJxcYULKayrO-_rE/Npk3iyaHaGMHYmOeFtt5sPUK1yU\""
}
Can anyone tell me where I'm doing it wrong?
谁能告诉我我做错了什么?
1 个解决方案
#1
2
You have to set the content type as "application/json" like below.
您必须将内容类型设置为“application / json”,如下所示。
client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
#1
2
You have to set the content type as "application/json" like below.
您必须将内容类型设置为“application / json”,如下所示。
client.Headers.Add(HttpRequestHeader.ContentType, "application/json");