duanfu1945 2018-09-27 12:07
浏览 103

发送数据Android Studio到PHP崩溃(&符号)

Cannot send complete string in Android Studio:

json_sales = "Client: blabla & net...."
HttpRequest req = null;
JSONArray products = null;
JSONObject json = null;
json_sales = json_sales.replace("
", " ");

HashMap<String, String> params = new HashMap<>();
params.put("data", json_sales);
params.put("tipo", "vd");

String l_resp = "";
try {
    req = new HttpRequest(server + "/importallsalses.php");
    l_resp = req.prepare(HttpRequest.Method.POST).withData(params).sendAndReadString();
} ...

file: importallsalses.php

<?php
    error_reporting(0);
    include "adodb5/adodb.inc.php";

    $data=$_POST["data"];
    $tipo=$_POST["tipo"];
    echo $data;
?>

Result - echo: "Client: blabla"

My problem is ampersand. How can I resolve this?

  • 写回答

1条回答 默认 最新

  • duanji1026 2018-09-27 12:23
    关注

    It looks like you are not encoding the ampersand & symbol before sending it.

    Using Javas URLEncoder is likely your friend here. Changing your params.put() assignment to the below should solve it:

    params.put("data", URLEncoder.encode(json_sales, "utf-8"));

    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办