Work notes - docking problems encountered in the tripartite Http Interface

I encountered many problems with third-party call HttpClient 4.4 http api, but fortunately finally resolved, the record about the problems encountered and solutions, hope to have this same problem you help.

Environment Description

First thing is, the other side of the test environment is deployed in a public network environment that is open, and required external network access, do not support the network, supports only go green (not currently considering this approach, because the laying of Line also time consuming consumption expenditure).

So debugging on the use of such an interface debugging tools POSTMAN at the time debug interface directly on a personal notebook.

In the letter the group and third-party micro FBI, tell each other what we need to call a few pieces of the interface, and then we follow to debug the interface documentation.

Debugging process found a lot of problems. For example, the other did not require oral or documented biography APPID, APPKEY and some other parameters, which is on the Head of the head, the three parties did not tell us in advance need these parameters, we found the interface when the FBI reported APPID not abnormal [ ] is empty, and then put the question to send the group, only half a day to reply, but inside they pass the buck to each other, So now before deciding who is going to solve.

Not that create a appid and the key thing in the system, the next day the afternoon to do a good job. This efficiency can not really say, but I feel that since working with us (we are a strong side), you'll need to have something ready, so what's the problem positive answer, solve, so efficiency is high.

This problem is solved, it needs an interface through POSTMAN soon have to debug it again, nothing big problems are normal by the FBI, the next step is through code calls, as well as handling some of the details of things.

Solution transmission file upload multipart / form-data request

Because the other side is to deploy the test environment outside the network, our company's development environment is within the company's network, and must be developed within the company's net (Rom database project otherwise not start), this problem is not a solution, so first the code will simply finish on your laptop, and then spread to the company's development machine.

Just started going to use Java comes  java.net.HttpURLConnection  that a way, but found the need to upload files, content-type needs to be adjusted when the second interface  multipart / form-data.

If you continue to use the set will be very troublesome in the java.net package, because upload files and general parameters are not the same, the need to split the file delimiters as well as general parameters, because the server needs to know where the end of the file where to start .

These need a client program to deal with, if it is to continue with the next class java.net package, will make this work to develop a lot of trouble, so in the end choose to use HttpClient toolkit to deal with this problem.

HttpClient is an open source project under the Apache Software Foundation, is more popular and easy to use http network requests kit, follow the principle of Java object-oriented programming. . . About HttpClient is not to say, want to know their own Baidu next.

HttpClient package transmission  multipart / form-data implementation details of the requested type, using the specific methods, see the article .

With the help of HttpClient, the basic code has been written and interfaces have been transferred by way of pass codes.

Solving agents and 400 Bad request

Then put the code uploaded to the company's development machine, ready to perfect some of the details of the deal.

These and other work done, commissioned colleagues opened to third-party proxy server IP network strategies have finished out (development machine, test environment are within the network environment, can not be directly connected Internet, it needs to access through a proxy server destination address, the time line is the same. our development machine can not access the proxy server, so only in a test environment test).

After deploying to the test environment after the submission of the code, I can not wait to test the. This is the first test of this feature, I remember it failed, error, 400 Bad request. What is the problem? Referring to this , but the Internet, said the two cases most, and I have does not match, so in this article also found a solution.

I go because the test environment agency, in his notebook when the FBI is directly connected to the Internet, so there is no problem. By looking at the code, I found the default HTTP protocol proxy settings when I use, and I want to access the target address is HTTPS, so I suspect this problem. So I put the target address to the HTTP request method (also supports other HTTP), really good. But this in turn raises other questions, let me see below.

Solve 502 Bad Getway 

The next lot of times, when tested again and found that most of the time reported that the timeout, Read timeout, because I set the time to wait for response is 10 seconds. After I get rid of this set, about 30 seconds, and returned error 502 Bad Getway

502 Bad Gateway error means gateway, the gateway is invalid; means a network error in the Internet. Page performance given in the WEB browser feedback.
Meaning: This usually does not imply that the upstream server is down (no response gateway / proxy), but upstream server and gateway / proxy protocol used to exchange data inconsistent. Given that the Internet protocol is quite clear, it often means that one or two machines have been incorrect or incomplete programming.

What is wrong? No start ah.

Thinking or agreement is not caused by the inconsistency? So I again http protocol in this regard to https, so the permutations and combinations of each other changed several times or not.

Then I found online a quick solution this problem, accidentally in line to see a foreign site was asked this question quick solution

One replied that [you may be using a proxy ssl to get content, but your proxy settings are wrong. You should consider using http as a proxy program, then use https as the actual content of the program. This solves my problem]

That's good standards, we do use a proxy.

Solve the certificate problem -javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection ?

So I changed the HTTP proxy, and then throw an exception: jvax.net.ssl.SSLException: the Message Unrecognized SSL, plaintext Connection?

Looked a bit mean, it does not recognize SSL information, plaintext connection? The original issue certificates aspects, to add the code to make it all trust certificates, specifically how to add reading this .

Then press article added trust all certificates just fine.

to sum up

Before Http interface is not too well, basically how not used, through this understanding to their knowledge in this area is lacking, to take mend.

 

Guess you like

Origin www.cnblogs.com/ibigboy/p/11251152.html