从 C# 应用程序读取 PHP 响应的安全方法

发布于 2024-12-17 19:04:49 字数 306 浏览 1 评论 0原文

正如该主题的标题所暗示的那样,我的服务器上设置了一个 PHP 脚本,当被调用时,它会通过将数据回显到页面上来将数据返回给用户。然后,我使用 HttpWebRequest 读取 PHP 脚本放入页面的数据。虽然此数据已加密,但我希望它根本不会出现在页面上。我想一定有更好的方法来做到这一点。

如果到目前为止我还不清楚我的意图,我正在寻找某种方法从 PHP 页面返回数据,以便我可以使用 HTTPWebResponse 检索它。例如,也许我可以发布数据?我对 PHP 很陌生,所以我想我应该询问这里的专家。

谢谢你的帮助,

埃文

As the title of the topic may suggest, I have a PHP script setup on my server that, when called upon, is spitting data back to the user by echoing it back onto the page. I am then using HttpWebRequest to read the data that was put onto the page by the PHP script. While this data is encrypted, I would like for it to not appear on the page at all. I figured there must be a better way to go about doing this.

If I have been unclear thus far regarding my intentions, I am looking for some way to return data from a PHP page, so that I can retrieve it using HTTPWebResponse. Perhaps, for example, I could POST the data? I'm quite new to PHP so I figured I'd ask the experts here.

Thank you for any help,

Evan

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

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

发布评论

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

评论(3

不美如何 2024-12-24 19:04:49

我认为最好的安全方法是在.NET 中使用 RSA 加密。您可以在此处阅读和下载项目

I think the best safe way is use RSA Encrypt in .NET. You can read and download project at here

铃予 2024-12-24 19:04:49

您无法将数据发布到应用程序,除非该应用程序是网络服务器。除了您已经这样做的方式之外,实际上没有其他方法可以做到这一点。

You can't post the data to the application, unless the application was a webserver. There's not really much other way to do it than the way you are doing it already.

深居我梦 2024-12-24 19:04:49

好吧,由于您使用的是 http,因此在 php 脚本中回显请求流中的数据是合乎逻辑的。这样另一边(您的 .NET 代码可以拾取它)。如果这对您来说是个问题,有一些解决方法。

a:使用指向您的 .NET 应用程序的回调 URL 从 .NET 调用您的 PHP 脚本。现在 PHP 脚本实际上可以将数据发送回回调 url。然而,这需要您的 .NET 应用程序托管 Web 服务。

b:您可以将某些数据放入您的 php 脚本中,而无需将其实际放入请求正文中,只需将其设置为 mime 标头字段,例如:

header('X-MyProject-Name: ' .$name);
header('X-MyProject-Age: ' .$age);
header('X-MyProject-Address: ' base64_encode(json_encode($complexAddressObject)));

希望这会有所帮助

Well, Since you're using http, it's logical to echo the data in the request stream within your php script. This way the other side (your .NET code can pick it up). If this is a problem for you, there are a few workarounds.

a: call your PHP script from .NET with a callback url refering back to your .NET application. Now the PHP script can actually post data back to the callback url. This however requires your .NET app to host a webservice.

b: you can put certain data in your php script without actually putting it in the request body by making it a mime header field like:

header('X-MyProject-Name: ' .$name);
header('X-MyProject-Age: ' .$age);
header('X-MyProject-Address: ' base64_encode(json_encode($complexAddressObject)));

Hope this helps

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