Link to home
Start Free TrialLog in
Avatar of deepu Lovelesh
deepu LoveleshFlag for India

asked on

What is the problem in below mentioned restsharp api json

kindly go through the below code and let me know where is the issue in the json format

Dim client = New RestClient("http://whatsapp.tsssoftware.com/api/sendPdf")
                client.Timeout = -1
                Dim request = New RestRequest(Method.POST)
                request.AddHeader("Content-Type", "application/json")
                'Dim jsonstring As String = Newtonsoft.Json.JsonConvert.SerializeObject(filebytes)
                request.RequestFormat = DataFormat.Json
                Dim jsonstring As String = request.JsonSerializer.Serialize(filebytes)
                'request.AddBody()
                request.AddParameter("application/json", "{" & vbLf & vbTab & """phone"":[""919416248146@s.whatsapp.net"", ""919416549905@s.whatsapp.net""]," & vbLf & vbTab & """key"":""XUhApSHBbN8HK92DibAb2nCPayjqngd0""," & vbLf & vbTab & """message"":""Hello, How are you?""," & vbLf & vbTab & """filename"":""hello.pdf""," & vbLf & vbTab & """image"":""data:application/pdf;base64,""" & jsonstring & """}", ParameterType.RequestBody)
                Dim response As IRestResponse = client.Execute(request)
                MsgBox(response.ResponseStatus)

the given response status is 1 but the pdf is not sent and message is not triggered.
please help its urgent.













Avatar of ste5an
ste5an
Flag of Germany image

Do not create JSON manually, when it's more complex than a single attribute. Use object serialization instead. Without debugging that, I would try removing the line feeds and tabulators.. looks to be promising candidates.
Avatar of deepu Lovelesh

ASKER

Dear Ste5an

Please help where it is in problem and what serialization to be used as i have already tried to serialize my object filebytes.
Create a class with the properties you need to send and serialize it.

See How to serialize and deserialize (marshal and unmarshal) JSON in .NET.
ASKER CERTIFIED SOLUTION
Avatar of deepu Lovelesh
deepu Lovelesh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Using a binary converter to bytes will for sure end in encoding issues..