PHP:通过 url 将参数发送到 Web 服务并获取响应

发布于 2024-10-08 11:53:31 字数 1000 浏览 0 评论 0原文

我知道如何从 Web 服务获取信息:连接(发送 url、用户和通行证)并使用 nusoap 调用向其传递参数的方法。这是一个例子:

$client = new nusoap_client($webServiceURL, 'wsdl', $proxyhost, $proxyport, $proxyusername, $proxypassword);

    $session_header = "<UserCredentials xmlns='http://page.net/Webservice/'><Userid>".$username."</Userid><Password>".$password."</Password></UserCredentials>";
    $client->setHeaders($session_header);

    $params = array('param_a'=> $var_a, 'param_b'=> $var_b);

    $result = $client->call('nameOfMethod', $params);

但我不知道如何通过网址发送信息:

我有一个注册表单,一旦提交,我必须发送:

请求: [base_path]/register/[name]/[address]/[email]/[phone]

响应:

OK(已注册): 标题内容:200; 正文内容 xml:

字段: [pass]

KO (未注册): 标头内容:401; body content XML:

<response>
<error>
[error number]
</error>
</response>

Fields: [错误号]

知道了这个,请跟我过一遍,表单提交后我该怎么办?正如你所看到的,我对此很陌生,而且完全迷失了。 多谢

I know how obtain info from a webservice: connecting (sending url, user and pass) and calling a method passing parameters to it using nusoap. Here's and example:

$client = new nusoap_client($webServiceURL, 'wsdl', $proxyhost, $proxyport, $proxyusername, $proxypassword);

    $session_header = "<UserCredentials xmlns='http://page.net/Webservice/'><Userid>".$username."</Userid><Password>".$password."</Password></UserCredentials>";
    $client->setHeaders($session_header);

    $params = array('param_a'=> $var_a, 'param_b'=> $var_b);

    $result = $client->call('nameOfMethod', $params);

But what I don't know is how to send info via url given this:

I have a registration form, and once it is submited I have to send:

Request:
[base_path]/register/[name]/[address]/[email]/[phone]

Response:

OK (is registered):
header content: 200;
body content xml:

Fields: [pass]

KO (is not registered):
header content: 401;
body content XML:

<response>
<error>
[error number]
</error>
</response>

Fields: [error number]

Knowing this, please follow me through it, what do I have to do after the form is submitted? As you see, I'm quite new to it and I'm totally lost.
Thanks a lot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

囍孤女 2024-10-15 11:53:31

我尝试使用 SOAP,但我错了(抱歉我正在学习)。我在这里所做的是创建一个 REST 请求。

到目前为止我已经完成了:

$request = "http://path.com/app/register/".$phone."/".$gender."/".$address."/". $name;
$response = file_get_contents($request); 

但是当我打印响应时我得到:
1d1ffaf569a8a6b3ddc5e88c1c219c22

如果响应正常,我应该在标头中得到 200,在正文中得到 xml。

当响应为 KO 时,我就明白了:

<response>
<error>
[error number]
</error>
</response>

OK 响应发生了什么?我是因为 file_get_contents 才得到它的?

如果可以,我还能用什么?我听说过 cURL 但不知道如何使用它:(

非常感谢

I was trying using SOAP, and I was wrong (sorry I'm learning). What I am doing here is creating a REST request.

I've done so far:

$request = "http://path.com/app/register/".$phone."/".$gender."/".$address."/". $name;
$response = file_get_contents($request); 

But when I print the response I get:
1d1ffaf569a8a6b3ddc5e88c1c219c22

When I should be getting a 200 in the headers and an xml in the body if the response is OK.

When the response is KO, I'm getting it right:

<response>
<error>
[error number]
</error>
</response>

What is happening with the OK response? I get it because of file_get_contents?

If so, what else can I use? I heard of cURL but have no idea on how to use it :(

Thanks a lot

野鹿林 2024-10-15 11:53:31

我不确定理解你的问题,但也许这可以帮助你:
http://php.net/manual/en/features.remote-files.php

甚至直接使用 simplexml:
http://php.net/manual/fr/function.simplexml-load -文件.php

I'm not sure to understand you question but maybe this can help you:
http://php.net/manual/en/features.remote-files.php

or even directly using simplexml:
http://php.net/manual/fr/function.simplexml-load-file.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文