Skip to content

Instantly share code, notes, and snippets.

@umiyosh
Created April 6, 2015 13:54
Show Gist options
  • Save umiyosh/b2b67d7e4cedb54606dd to your computer and use it in GitHub Desktop.
Save umiyosh/b2b67d7e4cedb54606dd to your computer and use it in GitHub Desktop.
javaのやつ
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
public class Main {
public static void main(String[] args) {
try {
StringWriter writer = new StringWriter();
writer.write("Service=AWSECommerceService");
writer.write('&');
writer.write("AWSAccessKeyId=AWSACCESSKEY");
writer.write('&');
writer.write("Operation=SellerListingSearch");
writer.write('&');
writer.write("SellerId=SELLERID");
writer.write('&');
writer.write("Title=TITLE");
writer.write('&');
writer.write("OfferStatus=Closed");
String content = writer.toString();
URL url = new URL("http://ecs.amazonaws.com/onca/xml");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(content.getBytes("UTF-8").length));
conn.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeBytes(content);
wr.flush();
wr.close();
System.out.printf("Response: %d %s\n", conn.getResponseCode(), conn.getResponseMessage());
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String input;
while ((input = br.readLine()) != null) {
System.out.println(input);
}
br.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment