1
My question is like this, I’m using Postman to simulate these requests, then when I choose there to show the code as it would be in java shows this code below, but full of "strange characters" like this WebKitFormBoundary7MA4YWxkTrZu0gW
, And if I remove them the requisition doesn’t work when I test here. Would anyone know what these codes are about, and how it would be the right way for me to send a post, with the data I want, a JSON for example, without having to add these codes, or at least some class or method that automatically generates these codes when sending the request?
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
RequestBody body = RequestBody.create(mediaType, "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"grant_type\"\r\n\r\npassword\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_id\"\r\n\r\ntestclient\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_secret\"\r\n\r\ntestpass\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"username\"\r\n\r\nchaves\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\ndiscovoador\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--");
Request request = new Request.Builder()
.url("http://api.sualoja.com.br/oauth")
.post(body)
.addHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW")
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "ae657120-da97-0123-ed66-bea56efdd3a8")
.build();
Response response = client.newCall(request).execute();
What are you asking? What is your question?
– Victor Stafusa
was bad, gave enter unintentionally here. If you have not well explained mt let me know to edit. And obr for editing my question.
– TheJ