I'm trying to populate our database using some curl command like
curl --user username:password https://somewebsite.com
curl - d "name=New User Name&address=New User Address" https://somewebsite.com/api/add/new
The instructions that they gave to me uses curl but I want to do it in Java so I decided to use HttpClient here's my code so far but with no luck with authorization. I keep getting an "Access Denied" but I'm pretty sure my credentials are correct.
DefaultHttpClient client = new DefaultHttpClient();
try{
client.getCredentialsProvider().setCredentials(new AuthScope(
"somewebsite.com", 443), new UsernamePasswordCredentials(username,password));
HttpPost postMethod = new HttpPost("https://somewebsite.com/api/add/new");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
populateVendor(nameValuePairs, data); //function to populate list
postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(postMethod);
InputStream stream = response.getEntity().getContent();
System.out.println("JSON RESPONSE: "+json);
//more functions to process JSON
}
finally{
client.getConnectionManager.shutdown();
}