Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to write curl call to Java?
    primarykey
    data
    text
    <p>I need to translate a curl call into Java. I keep getting a Java.io.FileNotFoundException. </p> <p>I have read all the related posts but nothing seems to work for me. Below you see the curl call and my Java code. Anybody has an idea what do i do wrong?</p> <p>A strange thing that I notice is that while I m trying to make PUT request:</p> <pre><code>conn.setRequestMethod("PUT"); </code></pre> <p>the value of the conn.method remains the default one "GET".</p> <p>Could you think of a reason why does this happen? </p> <pre><code>curl https://core.spreedly.com/v1/gateways/5GShuGwOJWX8fBSEojs7c8IpKaV/purchase.xml -u "user:secretKey" -H "Content-Type: application/xml" -d "&lt;transaction&gt;&lt;amount&gt;100&lt;/amount&gt;&lt;currency_code&gt;USD&lt;/currency_code&gt;&lt;payment_method_token&gt;token&lt;/payment_method_token&gt;&lt;/transaction&gt;" String url = "https://core.spreedly.com/v1/gateways/5GShuGwOJWX8fBSEojs7c8IpKaV/purchase.xml"; URL obj = new URL(url); HttpURLConnection conn = (HttpURLConnection) obj.openConnection(); conn.setRequestProperty("Content-Type", "application/xml"); conn.setDoOutput(true); conn.setRequestMethod("PUT"); String userpass = "user" + ":" + "secretKey"; String basicAuth = "Basic" + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes("UTF-8")); conn.setRequestProperty ("Authorization", basicAuth); String data = "&lt;transaction&gt;&lt;amount&gt;100&lt;/amount&gt;&lt;currency_code&gt;USD&lt;/currency_code&gt;&lt;payment_method_token&gt;token&lt;/payment_method_token&gt;&lt;/transaction&gt;"; OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(data); out.flush(); // Get the response BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = rd.readLine()) != null) { System.out.println(line);* } out.close(); rd.close(); } catch (Exception e) { System.out.print(e); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload