[英]How can I send a POST request with spaces?
I'm trying to send input from an edittext to PHP. 我试图将输入从edittext发送到PHP。 If I send in something with no spaces it works ok, but crashes with spaces and says this:
如果我发送的内容中没有空格,则可以正常工作,但是如果出现空格,则崩溃并显示以下内容:
illegal character
非法字符
...which refers to the space. ...指的是空间。
Obviously it's a matter of getting the quotes correct but for some reason I just can't get this right. 显然,这是使报价正确的问题,但是由于某些原因,我无法正确地做到这一点。
Where do I add the quotes? 我在哪里添加报价?
Is it in Java during creating the URL? 创建URL期间是Java吗?
http://example.com/android/project_group_notes_details.php?course=\'"+sessionCourse+"\'";
or while creating the Variable? 还是在创建变量时?
String sessionCouse = "\'Software Development With Spaces\'";
or is it somehow done server side? 还是以某种方式在服务器端完成?
A standard browser takes any spaces entered into the address bar and replaces them with %20
; 标准的浏览器会占用在地址栏中输入的所有空格,并将其替换为
%20
; HTML's space
character. HTML的
space
字符。
HTTP does not do this, the browser does, meaning that you have two options: HTTP不执行此操作,浏览器执行此操作,这意味着您有两个选择:
%20
; %20
; %20
%20
手动替换空格 For example: 例如:
String sessionCouse = "\'Software Development With Spaces\'";
should actually be 实际上应该是
String sessionCouse = "\'Software%20Development%20With%20Spaces\'";
以编程方式与后端服务器通信时,应使用URL编码对输入进行正确编码:
String fullURL = "http://example.com/android/project_group_notes_details.php?course=\'"+ URLEncoder.encode(sessionCouse, "UTF-8") + "\'";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.