I am using soap api request and its returning me this response.
That's my laravel controller code.
public function testResponseSRI($phone, $code)
{
$url = 'https://tamimahsms.com/user/bulkpush.asmx?wsdl';
$body = '
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SendSMS xmlns="https://www.tamimahsms.com/">
<UserName>username</UserName>
<Password>password</Password>
<Message>test message with code '.$code.'</Message>
<Priority>1</Priority>
<Schdate>07/18/2018</Schdate>
<Sender>AsifSource</Sender>
<AppID>123456</AppID>
<SourceRef>7654321</SourceRef>
<MSISDNs>'.$phone.'</MSISDNs>
</SendSMS>
</soap:Body>
</soap:Envelope>';
$headers = ['Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($body)];
$result = SoapClientRequest::send($url, $headers, $body);
return response()->json($result);
}
I want to get <StatusCode>00</StatusCode> from body object.
How can I get this?
Thanks
Finally, I figured out. The response was not a regular JSON, firstly convert it:
$data = $jsonResponse->getData();
Then treat it as a regular json. Now I can easily get <StatusCode>00</StatusCode> by using php preg_match
method like this:
if(preg_match("!<StatusCode>(.+)</StatusCode>!i",$data->body,$matches))
{
return $matches[1] // return 00
}
Related
I need to send XML requests in cypress but I don't know how to do that. Generally, I worked with cy.request with rest API's. Is it possible to send XML requests in cypress?
How can I do that? Any help would be great!! An example would be lovely!
I left an example request that I use in postman without a problem. But to automate my test I need to send that request in cypress.
(POST request)
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<MT_ServiceOrderInitiaionandMgmt xmlns:prx="***"
xmlns="***">
<VKONTO>***</VKONTO>
<NAME>***</NAME>
<PORTION>***</PORTION>
<AKLASSE/>
<DATUM>***</DATUM>
<Contact>
<RELTYP/>
<NAME>***</NAME>
<TEL_NUMBER>***</TEL_NUMBER>
<PHTYPE>***</PHTYPE>
<SMTP_ADDR>***</SMTP_ADDR>
</Contact>
<LifeSupportIndicator/>
<QMNUM>***</QMNUM>
<QMART>***</QMART>
<MNCOD>***</MNCOD>
<QMTXT>***</QMTXT>
<NOTST>***</NOTST>
<ServiceAddress>
<STREET>***</STREET>
<CITY1>***</CITY1>
<REGIO>***</REGIO>
<LOCATION>***</LOCATION>
<POST_CODE1>***</POST_CODE1>
<HAUS_NUM2/>
</ServiceAddress>
<ABLEINH>***</ABLEINH>
<CO_ASTTX>***</CO_ASTTX>
<STRMN/>
<STRUR>***</STRUR>
<LTRMN/>
<LTRUR>***</LTRUR>
<ERDAT>***</ERDAT>
<MZEIT>***</MZEIT>
<ERNAM>***</ERNAM>
<AEDAT/>
<AEZEIT>***</AEZEIT>
<AENAM/>
<PPSID>***</PPSID>
<ExternalReference>
<ID></ID>
<SYSNAME>***</SYSNAME>
<TYPE>***</TYPE>
</ExternalReference>
<REFNUM/>
<PRIOK/>
<LONT_TXT>***</LONT_TXT>
<PREMS>***</PREMS>
<Meters>
<TPLNR>***</TPLNR>
<VBSARTTEXT>***</VBSARTTEXT>
<TERMSCHL/>
<DLNOT>***</DLNOT>
<STORT>***</STORT>
<KTEXT>***</KTEXT>
<EINBDAT>***</EINBDAT>
<ISPRIM>***</ISPRIM>
<SERNR>***</SERNR>
<MET_SERNR></MET_SERNR>
<HERST>***</HERST>
<TYPBZ/>
<PREISKLA>***</PREISKLA>
<EQKTX>***</EQKTX>
<DSTAT>***</DSTAT>
<MEINS>***</MEINS>
<STANZVORE>***</STANZVORE>
<ISTABLART>***</ISTABLART>
<V_ZWSTAND></V_ZWSTAND>
<E_ZWSTANDO>***</E_ZWSTANDO>
<E_ZWSTANDU>***</E_ZWSTANDU>
<E_VERBERW>***</E_VERBERW>
<ADAT>***</ADAT>
<ATIM>***</ATIM>
<MTU_TPLNR/>
<MTUSN>***</MTUSN> >
<MTU_EQKTX/>
<MTU_EINBDAT>***11</MTU_EINBDAT>
<MTU_SERNR></MTU_SERNR>
<PORT>***</PORT>
</Meters>
</MT_ServiceOrderInitiaionandMgmt>
</soap:Body>
</soap:Envelope>
there are no big differences between standard rest API requests and XML Soap API requests.
cy.request({
method: "POST",
url: "Request URL",
headers: {
"Content-Type": "text/xml;charset=UTF-8",
authorization: "Bearer " + "auth token",
SOAPAction: "serviceOrder",
},
//you have to write your XML body here as a string. I leave a small part
//of my API's body to be an example if someone needs it in the future.
body: '<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><MT_ServiceOrderInitiaionandMgmt xmlns:prx="***" xmlns="***"><VKONTO>5883000</VKONTO><NAME>cypress</NAME><PORTION>MBC87<MTU_EINBDAT>2002-05-11</MTU_EINBDAT><MTU_SERNR></MTU_SERNR><PORT>1</PORT></Meters></MT_ServiceOrderInitiaionandMgmt></soap:Body></soap:Envelope>',
})
.then((res) => {
//Do something with the response.
});
I have applied for slideshare API and i got the API and the secret. All i have did is a simple GET request to slideshare which gives me results with the help of a tag.
This is my deluge script which i have tried to call the url using the API.
As per the documentation, i have got the unix time stamp and SHA1 hash.
param = Map();
param.put("api_key","XYZ");
param.put("ts","1565085930");
param.put("hash","xxxxxxxxxxxxxxxxxxxxxxxxx");
param.put("tag","cricket");
request = invokeurl
[
url :"https://www.slideshare.net/api/2/get_slideshows_by_tag"
type : GET
parameters: param
];
info request;
This is the response error i get:
<?xml version="1.0" encoding="UTF-8"?>
<SlideShareServiceError>
<Message ID="1">Failed API validation</Message>
</SlideShareServiceError>
Thank you.
Looks like the API does not work with a GET request. Try the same using a POST request and it should work. The same failed with POSTMAN and it worked only after the request type was changed to POST.
param = Map();
head = Map();
param.put("api_key","XXXXXXXX");
param.put("ts",1577955246);
param.put("hash","b3f3f803XXXXXXXXXXXXXXXX8be21d");
param.put("tag","cricket");
request = invokeurl
[
url :"https://www.slideshare.net/api/2/get_slideshows_by_tag"
type : POST
parameters: param
];
info request;
Response:
<?xml version="1.0" encoding="UTF-8"?>
<Tag>
<Name>cricket</Name>
<Count>0</Count>
</Tag>
Does anyone know how to extract html response from Guzzle HTTP client? If you look at the example below, we can get xml and json response easily but I don't know how to get plain text or HTML response string.
Documentation didn't have an option for plain text or HTML unlike json() and xml().
$client = new Client($base_url);
$request = $client->createRequest($method, $uri, null, $this->requestPayload);
$response = $client->send($request);
$xml = $response->xml(); // For XML response
$json = $response->json(); // For JSON response
$html = $response->????????(); // For plain text or HTML response
Solution:
This returns the whole response body as we see in browser.
$response->getBody(true)
How do I do a POST control request to the Amazon cloudfront API? In the docs it says:
Send a CloudFront control API request that is similar to the following example.
POST /2012-05-05/origin-access-identity/cloudfront HTTP/1.1
[Required headers]
<?xml version="1.0" encoding="UTF-8"?>
<CloudFrontOriginAccessIdentityConfig xmlns="http://cloudfront.amazonaws.com/doc/2012-05-05/">
<CallerReference>20120229090000</CallerReference>
<Comment>Your comments here</Comment>
</CloudFrontOriginAccessIdentityConfig>
I looked around for some information, and I am not sure how to do it. Is it something I can do via a Curl Request like here?
Any help very appreciated! I feel a little lost at the moment.
Many thanks!
Update
I do something like this now, still not working.. Any help?
<?php
$xml = 'POST /2012-05-05/origin-access-identity/cloudfront HTTP/1.1
Host: cloudfront.amazonaws.com
Authorization: [AWS authentication string]
Date: [time stamp]
[Other required headers]
<?xml version="1.0" encoding="UTF-8"?>
<CloudFrontOriginAccessIdentityConfig xmlns="http://cloudfront.amazonaws.com/doc/2012-05-05/">
<CallerReference>ref</CallerReference>
<Comment>The comment.</Comment>
</CloudFrontOriginAccessIdentityConfig>
';
$opts = array(
'http'=>array(
'method'=>'POST',
'header'=>"Content-Type: text/plain\r\n" .
$auth."\r\n",
'content'=>$xml
)
);
$context = stream_context_create($opts);
$url = 'https://cloudfront.amazonaws.com/2012-05-05/origin-access-identity/cloudfront';
$fp = fopen($url, 'r', false, $context);
fpassthru($fp);
$response = stream_get_contents($fp);
print_r($response);
fclose($fp);
?>
FireFox add-on Poster must help.
https://addons.mozilla.org/en-US/firefox/addon/poster/
Other similar tools:
Are there Firefox extension (or any other browser) that allow to send arbitrary POST data to a webpage?
After some changes in code and going through loads of links I was able to write the following code to call WCF service method with SOAP message. Now I get 400 Bad Request error, whatever I change (tried HttpWebRequest) I still get this error. Not sure what am I missing:
private string WebServiceCall()
{
WebRequest req = WebRequest.Create("http://klo239fu.mass.win.tf.com/WCFTestService/Service.svc");
req.ContentType = "application/soap+xml; charset=utf-8";
req.Method = "POST";
req.Headers.Add("SOAPAction", "http://tempuri.org/GetSimpleType");
using(Stream reqStream = req.GetRequestStream())
{
var bytes = Encoding.UTF8.GetBytes(txtFormattedSoap.Text);
reqStream.Write(bytes, 0, bytes.Length);
reqStream.Close();
}
var wr = (WebRespose)req.GetResponse();
var srd = new StreamReader(wr.GetResponseStream());
txtResponse.Text = srd.ReadToEnd();
}
SOAP Request (from SOAP client)
POST /WCFTestService/Service.svc HTTP/1.1
Host: klo239fu.mass.win.tf.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "wsf-test-service/IService/GetSimpleType"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetSimpleType xmlns="wsf-test-service">
<myvalue>int</myvalue>
</GetSimpleType>
</soap:Body>
</soap:Envelope>
Here is the SOAP request that is patterened to above soap enveope that I pass in my code:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetSimpleType xmlns="wcf-test-service"><myvalue>1234</myvalue></GetSimpleType></soap:Body></soap:Envelope>
Earlier I had content type test/xml but code throwed "(415) Cannot process the message because the content type 'text/xml' was not the expected type.". So I changed the content type="application/soap+xml; charset=utf-8" but it fails with (400) Bad request.
I'm saw antoher post you did and I think that you and I are currently working on the same thing. Invoking web services dynamically. Loading WSDLs, using dynamic proxies and reflection and all that fun stuff.
I have a suggestion for this error that you see.
I have had a similar issue with one of the web services I used. Even if the Action in the header is supposted to be optional, it did manage to get my call to fail when I passed in the address (uri) as you have. When I passed in the name of the operation instead it worked. So try and change this:
req.Headers.Add("SOAPAction", "http://tempuri.org/GetSimpleType");
To the name of the method in the WSDL instead. That is the name of the System.ServiceModel.Description.OperationDescription. It is probably "GetSimpleType".
req.Headers.Add("SOAPAction", "GetSimpleType");