Android Question Convert To httpjob Postring

Cassie

Member
Licensed User
Longtime User
Hi Guys,

Any body knows how to convert this HTTP post request

POST /index.php?route=api/custom/addProduct HTTP/1.1
Host: staging.test.com
key: EKBPhjMQOiqcV05qJzV2O
username: xxxx
product_name: This is a test product
price: 99999
model: LACOSTE
sku: 3
quantity: 1000
manufacturer_id: 5
category_id: 71
Cache-Control: no-cache
Postman-Token: 358f0cd8-52f0-46cf-aa64-555a32c9f71a
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

to httpjob post in b4j. Just little bit confused since it user header and not as body

Thanks in advance
 

Cassie

Member
Licensed User
Longtime User
Thanks for the response Erel.

How about this one which uses form-data on body

POST /index.php?route=api/custom/addProduct HTTP/1.1
Host: staging.xxxxxx.com
key: EKBPhjMQOiqcV05qJzV2OY2w
username: xxxx
Cache-Control: no-cache
Postman-Token: dadd6727-27e4-4b87-a2fd-a064a06ed764
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="product_name"

SAMSUNG KONI
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="price"

99999
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="model"

SAMSUNG
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="sku"

1XXXX1111
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="quantity"

9999
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="manufacturer_id"

5
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="category_id"

71
------WebKitFormBoundary7MA4YWxkTrZu0gW--

thanks in advance
 
Upvote 0

Cassie

Member
Licensed User
Longtime User
Getting an error of

main$ResumableSub_SyncWebProduct.resume (java line: 233)
java.lang.NullPointerException
at anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest.SetHeader(OkHttpClientWrapper.java:470)
at b4j.example.main$ResumableSub_SyncWebProduct.resume(main.java:233)
at b4j.example.main._v0(main.java:188)
at b4j.example.main._appstart(main.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at b4j.example.main.start(main.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)

see code below

B4X:
Sub AddNewProductToWeb
   Dim j As HttpJob
   Dim Link As String = "https://staging.test.com/index.php?route=api/custom/addProduct"
   Dim data As Map
   data.Initialize
   data.Put("product_name","This Is a test product")
   data.Put("price","This Is a test product")
   data.Put("model","SAMSUNG")
   data.Put("sku","37976979")
   data.Put("category_id","5")
   data.Put("manufacturer_id","71")
   j.Initialize("test", Me)
   j.GetRequest.SetHeader("Content-Type", "multipart/form-data")
   j.GetRequest.SetHeader("key","EKBPhjMQOiqcV05qJzV2OY2wdDHwSoBZ1fwc5")
   j.GetRequest.SetHeader("username","johndoe")
   j.PostMultipart(Link, data,Null)

   Wait For (j) JobDone(j As HttpJob)
   If j.Success Then
       'The result is a json string. We parse it and log the fields.
       Log(j.GetString)
       fx.Msgbox(MainForm, j.GetString,"")
   End If
   j.Release
End Sub

thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…