Web Services 计算查询字符串无法正常工作(php)

uelo1irk  于 2022-11-15  发布在  PHP
关注(0)|答案(1)|浏览(108)

必须从php调用GET-WS。
网址:https://testWS/CompanyGeneralInformation?IdUser=123&CUI=345
当query-string添加为静态时,它工作正常。
$out = file_get_contents("https://testWS/CompanyGeneralInformation?CUI=345&IdUser=123")
但当预先计算并作为参数传递时,得到错误

$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);

错误:

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

注:Seem id从服务器端转换为XML???进一步,当静态始终有效时,POST(通过curl)的自定义参数会出现相同的问题
通过 curl 过帐(错误)

$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()

注:WS文件规定:
GET /link/CompanyGeneralInformation?CUI=string&IdUser=string HTTP/1.1
响应是xml(但现在无关紧要)。
注意(错误源):Response is xml (but irrelevant now):非常相关,因为在使用WS获取id后,首先会出现错误,并且没有转换为变量。然后传递id(实际上是xml,因为没有解析)。

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
...

请让我知道可能是什么问题。

i7uaboj4

i7uaboj41#

从回显的注解和提到的错误来看,这似乎只是一个在通过URL传递XML之前没有从XML中提取所需信息的问题。

相关问题