我必须使用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="{'请求':{'应用程序':'我的应用程序id','身份验证':'api密钥','通知':[{'发送日期':'当前','忽略用户时区':true,'内容':'Hallo世界'}]}"
将myUri分为新Uri("https://cp.pushwoosh.com/json/1.3/")
Dim data=编码.UTF8.GetBytes(jsonSring)
Dim result_post=MyFunctions.SendRequest(myUri,data,"application/json","post")
功能:
公共共享函数SendRequest(uri作为uri,jsonDataBytes作为Byte(),contentType作为String,method作为String)作为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
您的URL似乎不完整。会是这样吗?
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等。