Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

android - Get java.net.SocketException: java.lang.IllegalStateException: No factory found. While trying to send POST request to HTTP server

I am writing an Android application in Android Studio which is sending a POST request to the server.

I have made a class for the HTTP connection:

public class PostTask extends AsyncTask {

    @Override
    protected Object doInBackground(Object[] objects) {
        Requester requester = new Requester();
        HttpClient httpclient =  new DefaultHttpClient();
        HttpPost httppost = new HttpPost("https://dev-api.shping.com/serialization-service/reassignment/task");
        HttpResponse response = null;
        HttpHost httpproxy = new HttpHost("hmkproxy1.fmlogistic.fr",8080);
        httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, httpproxy);

        try {
            httppost.setHeader("authenticateit_identity_ticket","63eb8926-e661-42c1-998d-3f008665c8e5");
            httppost.setHeader("cache-control","no-cache");
            httppost.setHeader("content-type", "application/json");

            StringEntity params = new StringEntity(requester.getJsonObject().toString());
            httppost.setEntity(params);

            // Execute HTTP Post Request
            response = httpclient.execute(httppost);
            System.out.println(response);
        } catch (ClientProtocolException e) {
            System.out.println("FUCK1");
        } catch (IOException e) {
            System.out.println(e);
        }
        return null;
    }
}

I am connecting through a proxy. I get this exception while my app works: java.net.SocketException: java.lang.IllegalStateException: No factory found Please help me, there is nearly no information about this exception on the internet. I tried to add some socket factories to my method, but it doesn't seems to work so I deleted them. Thanks!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...