Have to invoke a GET-WS from php
.
Url : https://testWS/CompanyGeneralInformation?IdUser=123&CUI=345
When query-string is added static it working properly.
$out = file_get_contents("https://testWS/CompanyGeneralInformation?CUI=345&IdUser=123")
But when is calculated in advance and passed as parameter, got error
$id=123;
$qs="https://testWS/CompanyGeneralInformation?CUI=345&IdUser=".$id;
$out = file_get_contents($qs);
//but this is OK
//$qs="https://testWS/CompanyGeneralInformation?CUI=345&IdUser=123";
//$out = file_get_contents($qs);
Error:
Warning: file_get_contents(https://...CompanyGeneralInformation?IdUser=<?xml version="1.0" encoding="utf-8"?>
<int xmlns="http://tempuri.org/">123</int>&CUI=567)
: Failed to open stream: HTTP request failed! HTTP/1.1 400
Note: Seem id is translated to XML from server-side ??? Further more get the same issues with custom parameter with POST(via curl), when static always work
Post via curl (error)
$str=strval("CUI=".$cui."&IdUser=".$id);
curl_setopt($ch, CURLOPT_POSTFIELDS,"$str"); //or either $str
System.Web.HttpRequestValidationException: A potentially dangerous Request.
Form value was detected from the client (IdUser="<?xml version="1.0" ...").
at System.Web.HttpRequest.ValidateString(String value, String collectionKey,
RequestValidationSource requestCollection) at
System.Web.HttpRequest.ValidateHttpValueCollection(HttpValueCollection collection,
RequestValidationSource requestCollection) at System.Web.HttpRequest.get_Form() at
System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest request) at
System.Web.Services.Protocols.HttpServerProtocol.ReadParameters() at
System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
Note: WS doc specify:
GET /link/CompanyGeneralInformation?CUI=string&IdUser=string HTTP/1.1
Response is xml (but irrelevant now).
Note(error source): Response is xml (but irrelevant now)
: very relevant since got the error after using WS to get id in first place and not transformed into a variable. Then id was passed (actually xml since not parsed).
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
...
Kindly let me know what could be the issue.
CodePudding user response:
From the comments of your echoing and the error mentioned, it does seem like this is simply an issue with not extracting the needed information from your XML before passing it via URL.