【问题标题】:Getting/Setting request property in HTTP request Android在 HTTP 请求 Android 中获取/设置请求属性
【发布时间】:2014-05-06 08:27:30
【问题描述】:

我在 android 的客户端设置了一些键值对,我如何在服务器端获取它。

代码:

               FileInputStream fileInputStream = new FileInputStream(sourceFile);
               URL url = new URL(upLoadServerUri);

               // Open a HTTP  connection to  the URL
               HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
               conn.setDoInput(true); // Allow Inputs
               conn.setDoOutput(true); // Allow Outputs
               conn.setUseCaches(false); // Don't use a Cached Copy
               conn.setRequestMethod("POST");
               conn.setRequestProperty("Connection", "Keep-Alive");
               conn.setRequestProperty("ENCTYPE", "multipart/form-data");
               conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
               conn.setRequestProperty("uploaded_file", fileName); 

               conn.setRequestProperty("uploaded_file", fileName);
               conn.setRequestProperty("key_1", "value_1"); 
               conn.setRequestProperty("key_2", "value?_2"); 
               conn.setRequestProperty("key_3", "value_3"); 

               conn.setRequestProperty("key_n", "value_n"); 

如何在php中获取key_1,key_2 ....key_n。

这些方法我都试过了

$_GET['key_1'];
$_REQUEST['key_1'];
$_POST['key_1'];
$_FILE['key_1'];

所有这些都不适合我,

请大家帮帮我。

【问题讨论】:

  • 你真的没有写['key']是吗?
  • 尝试写['key_1'] 2, 3, n
  • 表示我写的是 key_1,_key... key_n

标签: php android http-headers


【解决方案1】:

这些是标题,而不是发布或获取值。 您可能需要从 $_SERVER['']

读取它们

或者也检查这个帖子 How do I read any request header in PHP

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-11
    • 2017-03-10
    • 2016-03-10
    • 2012-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多