I have captured a post request through postman app
Although in postman it is correct and the output returns Json.
But at the same moment it gives an error in b4j with okhttputils
Could it be related to cookies?
Are all cookies deleted after the j.Release?
I think the main problem is getting the cookies from the previous request and placing them in the new request.
postman Code :
b4j Code :
Although in postman it is correct and the output returns Json.
But at the same moment it gives an error in b4j with okhttputils
Could it be related to cookies?
Are all cookies deleted after the j.Release?
I think the main problem is getting the cookies from the previous request and placing them in the new request.
postman Code :
B4X:
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"IsSymbolCautionAgreement\":false,\"CautionAgreementSelected\":false,\"IsSymbolSepahAgreement\":false,\"SepahAgreementSelected\":false,\"orderCount\":100,\"orderPrice\":2664,\"FinancialProviderId\":1,\"minimumQuantity\":0,\"maxShow\":0,\"orderId\":0,\"isin\":\"IRO1GMSH0001\",\"orderSide\":65,\"orderValidity\":74,\"orderValiditydate\":null,\"shortSellIsEnabled\":false,\"shortSellIncentivePercent\":0}");
Request request = new Request.Builder()
.url("https://example.com/Web/V1/Order/Post")
.method("POST", body)
.addHeader("sec-ch-ua", "\"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Google Chrome\";v=\"114\"")
.addHeader("Content-Type", "application/json")
.addHeader("DNT", "1")
.addHeader("sec-ch-ua-mobile", "?0")
.addHeader("Authorization", "BasicAuthentication 83d718c0-64e4-4ee2-a5d5-e10c7f966215")
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36")
.addHeader("sec-ch-ua-platform", "\"Windows\"")
.addHeader("Accept", "*/*")
.addHeader("Sec-Fetch-Site", "same-site")
.addHeader("Sec-Fetch-Mode", "cors")
.addHeader("Sec-Fetch-Dest", "empty")
.addHeader("host", "api.saderatbourse.ir")
.addHeader("Cookie", "f5avraaaaaaaaaaaaaaaa_session_=AAHBOFPMIICBAHPOJCPKLDJMONFFOHEIGCMKHNMCAIIKBECBMAPHGBNHINCACDFBCEODPKIDGFLEKDJBJOHAOBJPNKDOKFOEDDBMFCEJJIHFDLIAOKAHADLOKELOJKDJ; TS01633c3d=0180bb6f2230c5d097e0af3344117711bcb69386e54fa302598b660e72756c4cdb19117e527a79ec2a6c89812c67f0757533604290f6196593b12c280e74bf2f46cf71db48")
.build();
Response response = client.newCall(request).execute();
b4j Code :
B4X:
Sub SendBuyOrder
Dim url As String="https://example.com/Web/V1/Order/Post"
Dim objMap As Map
objMap.Initialize
objMap.Put("IsSymbolCautionAgreement", False)
objMap.Put("CautionAgreementSelected", False)
objMap.Put("IsSymbolSepahAgreement", False)
objMap.Put("SepahAgreementSelected", False)
objMap.Put("orderCount", 100)
objMap.Put("orderPrice", 2664)
objMap.Put("FinancialProviderId", 1)
objMap.Put("minimumQuantity", 0)
objMap.Put("maxShow", 0)
objMap.Put("orderId", 0)
objMap.Put("isin", "IRO1GMSH0001")
objMap.Put("orderSide", 65)
objMap.Put("orderValidity", 74)
objMap.Put("orderValiditydate", Null)
objMap.Put("shortSellIsEnabled", False)
objMap.Put("shortSellIncentivePercent", 0)
Dim objJSon As JSONGenerator
objJSon.Initialize(objMap)
Dim j As HttpJob
j.Initialize("j",Me)
j.PostString(url,objJSon.ToPrettyString(2))
j.GetRequest.SetContentType("application/json; charset=UTF-8")
j.GetRequest.SetHeader("Accept"," */* ")
j.GetRequest.SetHeader("Accept-Encoding","gzip, deflate, br")
j.GetRequest.SetHeader("Accept-Language"," en-US,en;q=0.9,fa;q=0.8 ")
j.GetRequest.SetHeader("Authorization", Token)
j.GetRequest.SetHeader("Connection","keep-alive")
j.GetRequest.SetHeader("Content-Length","373")
j.GetRequest.SetHeader("DNT","1")
j.GetRequest.SetHeader("Host","api.example.com")
j.GetRequest.SetHeader("Origin","https://example.com")
j.GetRequest.SetHeader("Referer","https://example.com/")
j.GetRequest.SetHeader("Sec-Fetch-Dest","empty")
j.GetRequest.SetHeader("Sec-Fetch-Mode","cors")
j.GetRequest.SetHeader("Sec-Fetch-Site","same-site")
j.GetRequest.SetHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36")
j.GetRequest.SetHeader("sec-ch-ua",$" "Not_A Brand";v="99", "Google Chrome";v="109", "Chromium";v="109" "$)
j.GetRequest.SetHeader("sec-ch-ua-mobile","?0")
j.GetRequest.SetHeader("sec-ch-ua-platform",$" "Windows" "$)
j.GetRequest.SetHeader("Cookie","f5avraaaaaaaaaaaaaaaa_session_=AAHBOFPMIICBAHPOJCPKLDJMONFFOHEIGCMKHNMCAIIKBECBMAPHGBNHINCACDFBCEODPKIDGFLEKDJBJOHAOBJPNKDOKFOEDDBMFCEJJIHFDLIAOKAHADLOKELOJKDJ; TS01633c3d=0180bb6f2230c5d097e0af3344117711bcb69386e54fa302598b660e72756c4cdb19117e527a79ec2a6c89812c67f0757533604290f6196593b12c280e74bf2f46cf71db48")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log(j.response.GetHeaders)
Log (j.Response.GetHeaders.Get("set-cookie"))
Log(j.Response.StatusCode)
Log(j.GetString)
'should return like this
' {
' "Data": Null,
' "MessageDesc": "any message.",
' "IsSuccessfull": False,
' "MessageCode": Null,
' "Version": 0
' }
End If
j.Release
End Sub
Last edited: