Java to POSTMAN or C#
Budget: $10 – $30 USD
I have the following code i want to understand what exactly happen to be apple to change to c#
notes: i try to do the same But submit put and add XML in the body and its rejected
see attached file
https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/use-case-guides/feeds-api-use-case-guide/feeds-api-use-case-guide_2021-06-30.md#upload-sample-code-java
// UploadExample.java
// This example is for use with the Selling Partner API for Feeds, Version: 2021-06-30
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
/**
* Example that uploads content.
*/
public class UploadExample {
public static void main(String args[]) {
String url = "<URL from the createFeedDocument operation>";
String content = "<your feed content>";
UploadExample obj = new UploadExample();
obj.upload(content.getBytes(StandardCharsets.UTF_8), url);
}
/**
* Upload content to the given URL.
*
* @param source the content to upload
* @param url the URL to upload content
*/
public void upload(byte[] source, String url) {
OkHttpClient client = new OkHttpClient();
// The contentType must match the input provided to the createFeedDocument operation. This example uses text/xml, but your contentType may be different depending upon on your chosen feedType (text/plain, text/csv, and so on).
String contentType = String.format("text/xml; charset=%s", StandardCharsets.UTF_8);
try {
Request request = new Request.Builder()
.url(url)
.put(RequestBody.create(MediaType.parse(contentType), source))
.build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) {
System.out.println(
String.format("Call to upload document failed with response code: %d and message: %s",
response.code(), response.message()));
}
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
notes: i try to do the same But submit put and add XML in the body and its rejected
see attached file
https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/use-case-guides/feeds-api-use-case-guide/feeds-api-use-case-guide_2021-06-30.md#upload-sample-code-java
// UploadExample.java
// This example is for use with the Selling Partner API for Feeds, Version: 2021-06-30
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
/**
* Example that uploads content.
*/
public class UploadExample {
public static void main(String args[]) {
String url = "<URL from the createFeedDocument operation>";
String content = "<your feed content>";
UploadExample obj = new UploadExample();
obj.upload(content.getBytes(StandardCharsets.UTF_8), url);
}
/**
* Upload content to the given URL.
*
* @param source the content to upload
* @param url the URL to upload content
*/
public void upload(byte[] source, String url) {
OkHttpClient client = new OkHttpClient();
// The contentType must match the input provided to the createFeedDocument operation. This example uses text/xml, but your contentType may be different depending upon on your chosen feedType (text/plain, text/csv, and so on).
String contentType = String.format("text/xml; charset=%s", StandardCharsets.UTF_8);
try {
Request request = new Request.Builder()
.url(url)
.put(RequestBody.create(MediaType.parse(contentType), source))
.build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) {
System.out.println(
String.format("Call to upload document failed with response code: %d and message: %s",
response.code(), response.message()));
}
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
Related categories:
C Programming
Business, Accounting, Human Resources & Legal
XML
Java ME
Java Tutoring