Can';t使用POST请求从Java向PHP发送数据
我试图使用POST请求将数据从Java代码发送到PHP代码。出于某种原因,在PHP方面我什么也得不到,但我的代码“正常”(没有异常发生)。有什么问题吗?提前谢谢! 我的数据如下所示:Can';t使用POST请求从Java向PHP发送数据,java,php,networking,Java,Php,Networking,我试图使用POST请求将数据从Java代码发送到PHP代码。出于某种原因,在PHP方面我什么也得不到,但我的代码“正常”(没有异常发生)。有什么问题吗?提前谢谢! 我的数据如下所示: "data=" + sb.toString() 代码如下所示: public static void sendRequest(String encryptedString) { HttpURLConnection connection = null; BufferedReader br = nul
"data=" + sb.toString()
代码如下所示:
public static void sendRequest(String encryptedString) {
HttpURLConnection connection = null;
BufferedReader br = null;
DataOutputStream dos = null;
try {
connection = (HttpURLConnection) new URL("http://localhost/something/function").openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setFixedLengthStreamingMode(encryptedString.length());
dos = new DataOutputStream(connection.getOutputStream());
dos.writeBytes(encryptedString);
dos.flush();
br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
System.out.println("Can't create connection...");
e.printStackTrace();
} finally {
try {
if(dos != null) dos.close();
if(connection != null) connection.disconnect();
if(br != null) br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
附:图片:
问题是我用SHA-1加密了整个数据=随机数。data=part不应加密,需要稍后添加。var_dump()PHP函数返回以下内容:null您没有将其发送到“PHP”,而是发送到web服务器(可能是Apache),因此您应该检查HTTP POST是否到达Apache。检查它的访问日志以验证这一点。我知道我正在将它发送到Web服务器,但我想说的是,我正在尝试将数据从Java代码传递到PHP代码。我会尽快检查日志,只要我有时间(如果我能在这个该死的wamp结构xD中找到它们的话),不过,谢谢你的建议我检查了日志,它说帖子通过了(200 OK)。我想问题一定出在PHP方面。或者出于某种原因,我的Java代码不会将必要的数据写入输出流