Home > Mobile >  API released by Shanghai transportation card balance, but OkHttp received is not a json object but H
API released by Shanghai transportation card balance, but OkHttp received is not a json object but H

Time:10-08

Inside the Postman test no problem, but that request back OkHttp does HTML code
The following is the result of Postman
Shanghai published interfaces and transportation card companies out of the results are sure


But Shanghai published interface printed is HTML code

Transportation card company that in most cases is not to print the log, a small number of cases show timeout
The following is a code
 @ Override 
Public View onCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View the View=inflater. Inflate (R.l ayout. Fragment_third, container, false);
The Button submitNumber=(Button) view. The findViewById (R.i d.s ubmit_number);
The EditText EditText=(EditText) view. The findViewById (R.i d.s ptc_number);
//access to enter the card number
Final String sptcNumber=editText. GetText (). The toString ();
SubmitNumber. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View View) {
SendRequestWithOkHttp (sptcNumber);
}
});
Return the view;
}

Public void sendRequestWithOkHttp (final String cardNumber) {
New Thread (new Runnable () {
@ Override
Public void the run () {
Try {
OkHttpClient client=new OkHttpClient ();
RequestBody RequestBody=new FormBody. Builder ()
. The add (" cardno ", cardNumber)
//. The add (arg1, cardNumber)
.build();
Request the Request=new Request. Builder ()
Url (" https://shanghaicity.openservice.kankanews.com/public/traffic/Jtkapi ")
//url (" http://www.sptcc.com/servlet/CardAmtServelet ")
. RemoveHeader (" the user-agent ")
AddHeader (" the user-agent ", "Mozilla/5.0 (Windows NT 10.0; Win64; X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari 537.36/OPR/62.0.3331.116 ")
.post (requestBody)
.build();
The Response the Response=client. NewCall (request). The execute ();
String responseData=(https://bbs.csdn.net/topics/response.body). The String ();
//System. Out. Println (responseData);
The d (TAG, responseData);
//parseJSONWithJSONObject (responseData);
} the catch (Exception e) {
e.printStackTrace();
}
}
}). The start ();
}

CodePudding user response:

Compare the postman request parameters and your okhttp request parameters

CodePudding user response:

Look at the address and the parameters can be right

CodePudding user response:

reference m - 1/f, oj response:
postman to contrast the request parameters and your request okhttp

I see review elements inside the display of the form data and others on the ios shortcut to write, see request parameters should be cardno this one, so I pass this a postman tried, found feasible after I 24-27 cardno a line will pass, but he will return a 404 page

CodePudding user response:

refer to the second floor zhang106209 response:
take a look at the address and the parameters for

Address is sure no problem, the parameter form data and others write shortcuts on ios, only one cardno, is just the incoming traffic card number, so I'll line 24-27 incoming is cardno, then return to the comment line pages point from the display is 404 not found

CodePudding user response:

refer to the third floor with too brother reply:
Quote: reference m - 1/f, oj response:

Compare the postman request parameters and your request okhttp

I see review elements inside the display of the form data and others on the ios shortcut to write, see request parameters should be cardno this one, so I pass this a postman tried, found feasible after I 24-27 cardno a line will pass, but he will return a 404 page


The postman's default request header is not the same as okhttp default, you will see the difference request header

CodePudding user response:

reference m - 5 floor oj response:
Quote: refer to the third floor with too brother reply:

Quote: reference m - 1/f, oj response:

Compare the postman request parameters and your request okhttp

I see review elements inside the display of the form data and others on the ios shortcut to write, see request parameters should be cardno this one, so I pass this a postman tried, found feasible after I 24-27 cardno a line will pass, but he will return a 404 page


The postman's default request header is not the same as okhttp default, you will see the difference request header

Okay, I see
  • Related