Safe way to read PHP response from C# application

╄→尐↘猪︶ㄣ 提交于 2019-12-11 06:18:20

问题


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


回答1:


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




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/8236454/safe-way-to-read-php-response-from-c-sharp-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!