我必须使用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':'我的app id','auth':'api key','notifications':[{'send_date':'now','ignore_user_timezone' :true,'content':'Hallo world'}}}}“
Dim myUri As New Uri(“https://cp.pushwoosh.com/json/1.3/”)
Dim data = 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
答案 0 :(得分:1)
您的网址似乎不完整。可能是这样吗?
Dim myUri As New Uri("https://cp.pushwoosh.com/json/1.3/")
应该是https://cp.pushwoosh.com/json/1.3/createMessage或https://cp.pushwoosh.com/json/1.3/registerDevice等等。