Hello,
Need to PostData to a URL and read the result. My code to PostData is and Read the response is
String ls_email, ls_einvoice_json
ls_email = test@test.com
ls_einvoice_json = /*JSONVALUE*/ This JSON is verified to work
ls_url = 'https://api.mastergst.com/einvoice/type/GENERATE/version/V1_03'
ls_url += '?email='
lb_url = Blob(ls_email, EncodingAnsi!)
ls_url += lo_coder.URLEncode(lb_url)
lo_client = Create HttpClient
lo_client.SetRequestHeader("gstin", '1')
lo_client.SetRequestHeader('username', '2')
lo_client.SetRequestHeader('auth-token', '3')
lo_client.SetRequestHeader('client_id', '4')
lo_client.SetRequestHeader('client_secret', '5')
lo_client.SetRequestHeader('ip_address', '6')
lo_client.SetRequestHeader("Content-Type", "multipart/form-data; boundary--------------------------359875084413580694217125")
lo_client.SetRequestHeader('Content-Length', String(Len(ls_einvoice_json)*2))
If lo_client.PostDataStart(ls_url) = 1 Then
li_PackCount = Round(Len(as_einvoice_json) / 1024, 0)
For i = 1 To li_PackCount
ls_NextData = Mid(as_einvoice_json, (i - 1) * 1024 + 1, 1024)
li_ret = lo_client.PostData(ls_NextData, Len(ls_NextData) * 2)
If li_ret <> 1 Then Exit
Next
li_ret = lo_client.PostDataEnd()
End If
If li_ret = 1 Then
li_StatusCode = lo_client.GetResponseStatusCode()
If li_StatusCode = 200 Then
li_ret = lo_client.GetResponseBody(ls_einvoice_ack_json)
If li_ret = -1 Then
ls_einvoice_ack_json = 'General Error'
ll_return = -1
ElseIf li_ret = -2 Then
ls_einvoice_ack_json = 'Code Conversion Failed'
ll_return = -1
End if
Else
ls_einvoice_ack_json = lo_client.GetResponseStatusText()
ll_return = -1
End If
Else
ls_einvoice_ack_json = of_httperrormessage(li_ret)
ll_return = -1
End If
I expect the GetResponseBody should give me the result. What I'm getting is blank string, with return value = -2.
Anything I'm missing?
Happiness Always
BKR Sivaprakash
Yes the missing one was
lnv_HttpClient.SetRequestHeader('Content-Type', 'application/json)
Setting this solved this issue.
Yes you are right, it's a type. It should be ls_einvoice_json and NOT as_einvoice_json. Issue of copy / paste, modify....
Just this one line, took me a day to figure out.
Thanks again.