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 parametersCodePudding user response:
Look at the address and the parameters can be rightCodePudding user response: