0

i am trying to send this JSON and it keep returns me false: Reason: NO TOKEN. Is there anything wrong with the JSON string?

URL

http://123.123.123.123/php/push/push.php

JSON (my third party ask me to put it in the body and in JSON format)

{
   "device":"Android",
   "message":"Testing",
   "Id":"15073116192095313120",
   "img":"",
   "token":[
      "DJISIODJOIS485uhhhifsejf9fdg"
   ]
}

SEND REQUEST (do I need the ?data=)

http://123.123.123.123/php/push/push.php?data={"device":"Android","message":"Testing","Id":"15073116192095313120","img":"","token":["DJISIODJOIS485uhhhifsejf9fdg"]}

CODE BEHIND

        Dim data As String

        data += "{""device"":""" + Device
        data += """,""" + "message"":""" + Message
        data += """,""" + "Id"":""" + ID

        If Device="Android" Then data += """,""" + "img"":""" + Img

        data += """,""" + "token"":[""" + token + """]"
        data += "}"

        Dim URL As String = Convert.ToString(http://123.123.123.123/php/push/push.php & "?") + data

        ' ## Perform an HTTP Get Request
        Dim response As String = PerformHTTPGet(URL)
Ken Y-N
  • 14,644
  • 21
  • 71
  • 114
belltric
  • 115
  • 2
  • 15
  • Why is the token being passed an array of string values? Is that right? – Ian Mercer Sep 08 '15 at 02:48
  • yep, they gave me the format in [] – belltric Sep 08 '15 at 02:52
  • It seems unlikely that a field named "token" would be an array. You need to talk to whoever owns this API, this isn't something StackOverflow users can help you with. – Ian Mercer Sep 08 '15 at 03:04
  • I'm voting to close this question as off-topic because this isn't something StackOverflow users can help with. – Ian Mercer Sep 08 '15 at 03:04
  • 1
    You might need to encode the `data` portion of the URL; [vb.net has functions for this](https://msdn.microsoft.com/en-us/library/zttxte6w(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2). – Ken Y-N Sep 08 '15 at 03:15
  • token is an array field. token:[abc, cde,efg] – belltric Sep 08 '15 at 03:15
  • Or, as I see you say "my third party ask me to put it in the body and in JSON format", [here is a short routine](https://gist.github.com/six519/5ed917850f402b94ee6b) for POSTing JSON. – Ken Y-N Sep 08 '15 at 03:21
  • possible duplicate of [Post JSON on URL HTTP Web Request with VB.NET](http://stackoverflow.com/questions/24457191/post-json-on-url-http-web-request-with-vb-net) – Ken Y-N Sep 08 '15 at 03:23
  • yep already encoded the data and it works xD – belltric Sep 08 '15 at 03:26
  • I encoded with the below code Dim httpWReq As HttpWebRequest = DirectCast(WebRequest.Create(URL & "?"), HttpWebRequest) Dim encoding As New ASCIIEncoding() Dim postData As String postData += EncodedData Dim data As Byte() = encoding.GetBytes(postData) httpWReq.Method = "POST" httpWReq.ContentType = "application/json" httpWReq.ContentLength = data.Length Using stream As Stream = httpWReq.GetRequestStream() stream.Write(data, 0, data.Length) End Using – belltric Sep 08 '15 at 03:41

0 Answers0