java - Trying to download data from a password protected website -


i have url data access. data in text form , password protected...but here's thing...it password protected login on different website. every time try gain access data url, http 500 error. suggestions issue? don't think common problem considering have not come across in many stackoverflow , google searches.

below example of 1 of programs have tried using no avail...(some of information private, changed username, password, , url)

package apache1; //import org.apache.http.*; import org.apache.http.auth.authscope; import org.apache.http.auth.usernamepasswordcredentials; import org.apache.http.client.credentialsprovider; import org.apache.http.client.methods.closeablehttpresponse; import org.apache.http.client.methods.httpget; import org.apache.http.impl.client.basiccredentialsprovider; import org.apache.http.impl.client.closeablehttpclient; import org.apache.http.impl.client.httpclients; import org.apache.http.util.entityutils;  import java.net.*;  import java.io.*;  /**  * simple example uses httpclient execute http request against  * target site requires user authentication.  */ public class apache2 {     public static void main(string[] args) throws exception {         credentialsprovider credsprovider = new basiccredentialsprovider();         credsprovider.setcredentials(                 new authscope("localhost", 443),                 new usernamepasswordcredentials("myusername", "mypassword"));         closeablehttpclient httpclient = httpclients.custom()                 .setdefaultcredentialsprovider(credsprovider)                 .build();         try {             httpget httpget = new httpget("login_website");             system.out.println("executing request " + httpget.getrequestline());             closeablehttpresponse response = httpclient.execute(httpget);             try {                 system.out.println("----------------------------------------");                 system.out.println(response.getstatusline());                 entityutils.consume(response.getentity());                          url oracle = new url("data_website");                         urlconnection yc = oracle.openconnection();                         bufferedreader in = new bufferedreader(new inputstreamreader(                                                     yc.getinputstream()));                         string inputline;                         while ((inputline = in.readline()) != null)                              system.out.println(inputline);                         in.close();              } {                 response.close();             }         } {             httpclient.close();         }     } } 


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -