質問

I'm new to using REST services and I'm using apigee.com to test GET and POST requests for my REST service.

My question is, how can I test my POST request by passing parameters to create the new record?

I can run my GET request successfully and I get back a JSON response with the records requested.

When I try my post request, I'm getting an error:

"message": "Content-Type header specified in HTTP request is not supported: application/x-www-form-urlencoded; charset=UTF-8",
"errorCode": "UNSUPPORTED_MEDIA_TYPE"

Here is my class method:

@HttpPost
global static Merchandise createMerchandise(String name, String description, Double price, Integer totalInventory) {
    System.Debug('POST /merchandise/*');

    Merchandise__c merchandise = new Merchandise__c();
    merchandise.Name = name;
    merchandise.Description__c = description;
    merchandise.Price__c = price;
    merchandise.Total_Inventory__c = totalInventory;

    insert merchandise;

    Merchandise merch = castToMerchandise(merchandise);

    return merch;
}

How do I pass the parameters in the URL and how do I specify the correct content type using the agigee console to test my service?

Thanks for any help.

役に立ちましたか?

解決

You should look in to the format that you are having your Rest service accept and add "x-www-form-urlencoded" if you are going to continue using it to send payloads to the URL.

You specify the Content-Type under the Headers tab in the Apigee console, you just need to look in to what the Content-Type the server accepts.

To pass parameters in the url you just attach ? to the end of the Url and put the variable names and values. These are usually called queryStrings like so:

www.example.com?name=Dman100&Rep=104.

This example will pass to variables name and Rep. When passing variables in the URL you must be careful to html url encode the variables and their values.

For Posts you send the content in the payload/body. In whatever format is necessary.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top