doutang3760 2015-03-17 11:12
浏览 131
已采纳

如何发送带空格的POST请求?

I'm trying to send input from an edittext to 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?

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?

  • 写回答

2条回答 默认 最新

  • dongyi1748 2015-03-17 11:29
    关注

    A standard browser takes any spaces entered into the address bar and replaces them with %20; HTML's space character.

    HTTP does not do this, the browser does, meaning that you have two options:

    1. Create a function to take in a string and replace all spaces with %20;
    2. Manually replace spaces with %20

    For example:

    String sessionCouse = "\'Software Development With Spaces\'";
    

    should actually be

    String sessionCouse = "\'Software%20Development%20With%20Spaces\'";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料