简体   繁体   English

如何从 escaping 报价中停止 HTTP ?

[英]How can I stop HTTP from escaping quotes?

I'm using C# to POST some data to a webserver running PHP.我正在使用 C# 将一些数据发布到运行 PHP 的网络服务器。

I'm sending a JSON formatted object to the server in the POST data.我在 POST 数据中将 JSON 格式的 object 发送到服务器。

The data looks something like this when it leaves the C# program:当它离开 C# 程序时,数据看起来像这样:

json_text={"abc":"hello", "dfg":"world"}

I have the server printing the data exactly as it received it using echo $_POST['json_text'];我让服务器使用echo $_POST['json_text']; 完全按照接收到的数据打印数据; The script outputs the following:该脚本输出以下内容:

{\"abc\":\"hello\", \"dfg\":\"world\"}

I'm not very familiar with how POST data is packaged into an HTTP packet.我不太熟悉 POST 数据是如何打包到 HTTP 数据包中的。 I opened up WireShark to look at how quotes are sent in POST data and it looks like they are replaced with %22 .我打开 WireShark 来查看如何在 POST 数据中发送引号,看起来它们被替换为%22 However, I tried replacing my quotes with %22 and it did NOT stop the quotes from being escaped when it is outputted.但是,我尝试用 %22 替换我的引号,它并没有阻止引号在输出时被转义。

Thank you谢谢

Turn off PHP's magic_quotes option.关闭 PHP 的magic_quotes选项。 That's probably where the backslashes are coming from.这可能是反斜杠的来源。

Setup your json_text object as follows, not quoting the property names and using single quotes instead:如下设置您的json_text object,不引用属性名称,而是使用单引号:

json_text = { abc: 'hello', dfg: 'world' }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM