我必须使用 pushwoosh api 向设备发送消息。我从 vb.net 发送它,我有一个高级帐户。该代码工作正常,但我从服务器返回代码 400。有任何想法吗?
我的 json 请求如下所示:
{
'request':
{
'application':'xxxxx-xxxxx',
'auth':'xxxxx',
'notifications':[{
'send_date':'now',
'ignore_user_timezone': true,
'content':'Hallo world'
}]
}
}
VB.net 代码:
来电:
dim JsonSring = "{'request':{'application':'My app id','auth':'api key','notifications':[ {'send_date':'now','ignore_user_timezone': true, '内容':'你好世界'}]}}"
将 myUri 调暗为新 Uri(" https://cp.pushwoosh.com/json/1.3/ ")
暗淡数据 = Encoding.UTF8.GetBytes(jsonSring)
Dim result_post = MyFunctions.SendRequest(myUri, data, "application/json", "POST")
功能:
公共共享函数 SendRequest(uri As Uri, jsonDataBytes As Byte(), contentType As String, method As String) As String
Dim req As WebRequest = WebRequest.Create(uri)
req.ContentType = contentType
req.Method = method
req.ContentLength = jsonDataBytes.Length
Dim stream = req.GetRequestStream()
stream.Write(jsonDataBytes, 0, jsonDataBytes.Length)
stream.Close()
Dim response = req.GetResponse().GetResponseStream()
Dim reader As New StreamReader(response)
Dim res = reader.ReadToEnd()
reader.Close()
response.Close()
Return res
End Function