gpt4 book ai didi

java - 使用 HTTP URL 将文件名从 Java 传递到 PHP

转载 作者:行者123 更新时间:2023-12-02 00:56:13 25 4
gpt4 key购买 nike

我想使用 SFTP 从 Java 上传文件,并使用 PHP 脚本上传文件路径,但问题是我没有在文本框中获取 PHP 脚本中的路径,但在我的 IDE 中,路径显示

直接使用 SFTP 上传没问题,但文件路径未显示在我的 PHP 文本框中*

JAVA代码

BufferedReader in;
boolean blResult = sftpBean.connect("xx.xxx.xx.x", xx, "xxxx", "xxxx");
if (blResult) {
System.out.println("Successfull Connection");
String path="/home/folder/upload/";
String p="http://xx.xxx.xx.x/upload/";
blResult = sftpBean.uploadFile(data,result,path);
if(blResult) {
OutputStream os = null;
InputStream is = null;
URL url = new URL("http://xx.xxx.xx.x/folder/test.php?test="+p+result);
URLConnection conn = url.openConnection();
conn.connect();
in = new BufferedReader(newInputStreamReader(conn.getInputStream()));
String inputLine;
while((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();

PHP 代码 test.php

<?php
$path=$_GET['test'];
echo "<input type='text' value='$path'>";
?>

预期结果是路径名将显示在我的 php 文本框中到目前为止,结果仅显示在我的 IDE 中

最佳答案

你应该encode您的查询参数。

String testParameterEncoded = URLEncoder.encode(p + result, StandardCharsets.UTF_8);
URL url = new URL("http://xx.xxx.xx.x/folder/test.php?test=" + testParameterEncoded);

关于java - 使用 HTTP URL 将文件名从 Java 传递到 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57816894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com