Passing parameters to WCF restful service with POST method - fiddler

how can I use Fiddler to pass 2 parameters to a method with a signature like this :
[WebInvoke(UriTemplate = "Login", Method = "POST", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
bool Login(string login, string password);
Any suggestion to change something in the method is welcome, but I have always to pass 2 string parameters.

It is much easier to the services with WCFTestClient. Anyway, Fiddler has composer functionality which can be used to test any http calls.
Request Headers should look like below. Just change SOAPAction accordingly.
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tempuri.org/IService/Login"
Host: localhost:2045
Content-Length: 179
Expect: 100-continue
Accept-Encoding: gzip, deflate
Proxy-Connection: Keep-Alive
And request body:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><Login xmlns="http://tempuri.org/"><login>sdf</login><password>sdf</password></Login></s:Body></s:Envelope>

Related

vscode-restclient How to process / parse response body

The vscode extension vscode-restclient allows to create http request and handle the response similar to curl or postman.
A POST request to /sales/getResult/ returns this response
HTTP/1.1 200 OK
Date: ....
Content-Type: text/plain; charset=utf-8
Content-Length: 67
Connection: close
Load your results with ID: CJoYTvh8
From the body we need the id CJoYTvh8 to get details. The request to get details goes to the URL /sales/GetResult/{{resultId}} . Where {{resultId}} stands for the ID CJoYTvh8 from the previous response body.
I want to create the request for the details which needs to look like this
#resultId = {{myRequest.response.body}} // this should only be CJoYTvh8
# #name getResult_for_id
POST /sales/getResult/{{resultId}} HTTP/1.1
Host: {{our_host}}
Authorization: Bearer {{authToken}}
Content-Type: application/json
I am looking for something like this
#resultId = response.body.split(':')[1].trim()
Question
How can i split the string Load your results with ID: CJoYTvh8 in vscode-restclient so that i assign only the id CJoYTvh8 to the variable #resultId?

Delphi: set Content-type of TCustomRestRequest on PUT

I'm fighting a REST API call from Delphi. I want to send a PUT request to a server, with contenttype set to application/json:
aCustomRestClient.BaseURL := domein;
aCustomRestRequest.Client := aCustomRestClient;
aCustomRestRequest.Response := aCustomRestResponse;
aCustomRestRequest.Method := rmPUT;
aCustomRestRequest.Resource := '/service/API/1501/allowanceCategory';
aCustomRestRequest.Params.AddHeader('sessionId', SessionToken);
qryAllowanceCategory.First;
o := TJSONObject.Create;
arr:=TJSONarray.create;
try
o.AddPair('createdBy',qryAllowanceCategory.fieldbyname('createdBy').AsString);
{lot more pairs here}
o.AddPair('percentage', TJSONnumber.create(qryAllowanceCategory.fieldbyname('percentage').AsFloat));
o.AddPair('remark', 'JUR '+ qryAllowanceCategory.fieldbyname('remark').AsString);
arr.add(o);
aCustomRestRequest.ClearBody;
aCustomRestResponse.contenttype:='application/json';
aCustomRestClient.contenttype:='application/json';
aCustomRestRequest.AddBody(arr.ToString);
aCustomRestRequest.Execute;
However, when I view my request as sent with Fiddler:
PUT http://shadow.jdvretail.com/service/API/1501/allowanceCategory HTTP/1.1
Connection: Keep-Alive
Content-Type: application/x-www-form-urlencoded
Accept: application/json, text/plain; q=0.9, text/html;q=0.8,
Accept-Charset: utf-8, *;q=0.8
Authorization: Basic <<Authorization properly filled>>
User-Agent: Embarcadero RESTClient/1.0
sessionId: <<sessionID GUID properly filled here>>
Content-Length: 542
The Content-type remains wrong... how/where do I correctly set the contentType to 'application/json'?
TRestClient.AddBody(<string>) has an optional second parameter allowing to set the content type.
procedure AddBody(const ABodyContent: string; AContentType: TRESTContentType = ctNone); overload;

Load performance testing with Gatling and Content-Type

I am using gatling for load performance testing on a brand new API. It seems fairly easy and well documented but I am facing an issue as simple as POST a request with Content-Type set to 'application/vnd.api+json' on the Header. All works well when doing the GET stuff but when launching a POST test I get a
HTTP response:
status=
415 Unsupported Media Type
headers=
cache-control: [no-cache]
Content-Type: [application/vnd.api+json; charset=utf-8]
Date: [Fri, 08 Sep 2017 12:57:10 GMT]
Server: [nginx]
Vary: [Origin]
x-content-type-options: [nosniff]
x-frame-options: [SAMEORIGIN]
X-Request-Id: [ff993645-8e01-4689-82a8-2f0920e4f2a9]
x-runtime: [0.040662]
x-xss-protection: [1; mode=block]
Content-Length: [218]
Connection: [keep-alive]
body=
{"errors":[{"title":"Unsupported media type","detail":"All requests that create or update must use the 'application/vnd.api+json' Content-Type. This request specified 'application/json'.","code":"415","status":"415"}]}
Here is the scala code I am using for the http request:
object PostTokenGcm {
val token = exec {
http("TestAPI POST /tokens")
.post("/tokens")
.headers(Map("Authorization" -> testApiToken,
"Content-Type" -> "application/vnd.api+json",
"Accept" -> "application/vnd.api+json" ))
.body(StringBody(gcmTokenRequestBody)).asJSON
.check(status.is(201))
.check(bodyString.exists)
}}
It seems that it is not setting the Content-Type?
Thank you for any lead!
In your POST definition you're using asJSON. According to notes in documentation about request headers:
http("foo").get("bar").asJSON is equivalent to:
http("foo").get("bar")
.header(HttpHeaderNames.ContentType, HttpHeaderValues.ApplicationJson)
.header(HttpHeaderNames.Accept, HttpHeaderValues.ApplicationJson)
... so, headers set in:
.headers(Map("Authorization" -> testApiToken,
"Content-Type" -> "application/vnd.api+json",
"Accept" -> "application/vnd.api+json" ))
... get overwritten by asJSON to "application/json" (which is the value of HttpHeaderValues.ApplicationJson).

Titanium multipart file upload with different content types?

So I am trying to post to a Salesforce.com REST api that is expecting the following sample request -
POST /services/data/v33.0/chatter/feed-elements HTTP/1.1
Authorization: OAuth 00DRR0000000N0g!...
User-Agent: Jakarta Commons-HttpClient/3.0.1
Host: instance_name
Content-Length: 845
Content-Type: multipart/form-data; boundary=a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq
Accept: application/json
--a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq
Content-Disposition: form-data; name="json"
Content-Type: application/json; charset=UTF-8
{
"body":{
"messageSegments":[
{
"type":"Text",
"text":"Please accept this receipt."
}
]
},
"capabilities":{
"content":{
"description":"Receipt for expenses",
"title":"receipt.pdf"
}
},
"feedElementType":"FeedItem",
"subjectId":"005RR000000DmOb"
}
--a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq
Content-Disposition: form-data; name="feedElementFileUpload"; filename="receipt.pdf"
Content-Type: application/octet-stream; charset=ISO-8859-1
...contents of receipt.pdf...
--a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq--
As you can see, the two parts of the request is expecting different content types.
In Titanium, I have the following code -
xhr.open("POST", postUri);
xhr.setRequestHeader("Authorization", authHeader);
xhr.setRequestHeader('enctype', 'multipart/form-data');
var data2send = {
json: jsonObj,
feedElementFileUpload: imageBlob
};
xhr.send(data2send);
According to the Appcelerator documentation and a couple of online threads, the httpclient should be able to set each part automatically, however, Salesforce API still gives an error message of:
[{"errorCode":"MISSING_ARGUMENT","message":"Missing required 'subjectId' parameter."}]
I can confirm that subjectId is in the jsonObj and its content is correct. It seems that the json part is not recognised as JSON by Salesforce correctly. How can I set the content-type correctly? Many thanks.
Updates - I used the Wireshark to capture the request text. Apparently the httpclient did not set up the content-type for the json part that Salsforce API is expecting. Any idea how to set it?
POST /services/data/v33.0/chatter/feed-elements HTTP/1.1
Host: mydomain.com
Accept-Language: en-us
User-Agent: Appcelerator Titanium/3.5.1 (iPhone Simulator/8.2; iPhone OS; en_US;)
enctype: multipart/form-data
X-Requested-With: XMLHttpRequest
Accept: */*
Content-Type: multipart/form-data; charset=utf-8; boundary=0xTibOuNdArY_1430987526
Connection: keep-alive
Authorization: Bearer $My_AUTH_CODE
X-Titanium-Id: 8329dd1d-3379-4d7c-955e-120ad1586a2b
Content-Length: 93333
Accept-Encoding: gzip, deflate
--0xTibOuNdArY_1430987526
Content-Disposition: form-data; name="json"
{"feedElementType":"FeedItem","subjectId":"xxxxxxxxxx","body":{"messageSegments":[{"type":"text","text":"test"}]},"capabilities":{"content":{"description":"sdfaadfs","title":"adsfafsd.png"}}}
--0xTibOuNdArY_1430987526
Content-Disposition: form-data; name="feedElementFileUpload"; filename="01430987526.png"
Content-Type: image/png
my file data...

SOAP UI - Split HTTP Response Header and transfer to property

I am obtaining the following response to a HTTP Request in SOAP UI
TTP/1.1 201 Created
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Location: /api/authorization_servers/5362c2c46362f0e7f33379e8
Content-Type: application/json
Transfer-Encoding: chunked
I would like to get the value of 5362c2c46362f0e7f33379e8 in the Location Response Header and transfer it to a Project property called "token". Can someone tell me how I am going to do that?
I am able to get the entire /api/authorization_servers/5362c2c46362f0e7f33379e8 into a variable through Groovy script in this way:
def headerValue = testRunner.testCase.getTestStepByName("Register Authorization Server").httpRequest.response.responseHeaders["Location"]
I am not able to proceed any further. Any help is greatly appreciated!
You have several options if I understand you right.
You could split the value and take the last element:
headerValue = headerValue.split( '/' )[ -1 ]
You could subtract the beginning of the header:
headerValue = headerValue - '/api/authorization_servers/'
Or you could use a regular expression:
headerValue = headerValue.find ~/[a-f0-9]+$/