gpt4 book ai didi

java - 从 http 客户端获取 404

转载 作者:行者123 更新时间:2023-12-01 14:03:13 25 4
gpt4 key购买 nike

这里我使用 HTTP-CLIENT 来调用 servlet,但是如果我只是单击“http://:8080/RemediPRMS/WritePingData”这个链接,它会给我响应代码 200,但如果我从小程序运行它,它会给我 404 .

    Deployment descriptor mapping is :
<servlet>
<servlet-name>WritePingData</servlet-name>
<servlet-class>com.clientToServer.FileUploader.WritePingData</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WritePingData</servlet-name>
<url-pattern>/WritePingData</url-pattern>
</servlet-mapping>

try{
System.out.println("folder.listFiles().length"+folder.listFiles().length);
if(folder.listFiles().length > 0){
System.out.println("inside if file found[][][[[][][][][][][");
String remediEndpoint = "http://<endpoint>:8080/RemediPRMS/WritePingData";
FileInputStream fis = null;
System.out.println("above for loop");
File arr[] =folder.listFiles();//file array
System.out.println("array pass");

PostMethod post = null;
System.out.println("just above for loop");
for(int i=0;i<arr.length;i++){
try{
System.out.println("inside for loop");
File targetFile = new File(path+"\\"+arr[i].getName());
fis = new FileInputStream(targetFile);
post = new PostMethod(remediEndpoint);
post.setRequestEntity(new InputStreamRequestEntity(fis, targetFile.length()));
post.setRequestHeader("Content-type","text/plain; UTF-8");
HttpClient httpclient = new HttpClient();
httpclient.setConnectionTimeout(10000);
int status = httpclient.executeMethod(post);
fis.close();
//boolean deletestatus= targetFile.delete();
System.out.println("status from server : "+status);
}catch(Exception e){
LOGGER.info("Exception in file upload (http client): "+e);
}
}
post.releaseConnection();
}else{
LOGGER.info("THERE IS NO MORE FILE TO UPLOAD ");
}
}catch(Exception e){
LOGGER.info("No directory inside LogData: "+e);
}

最佳答案

您需要在网址中输入主机名

例如

http://myserver:8080/RemediPRMS/WritePingData

或者假设您是,仍然处于沙盒状态的小程序不能

他们无法连接到任何第三方服务器(除了其来源服务器之外的任何服务器)或从任何第三方服务器检索资源。

参见http://docs.oracle.com/javase/tutorial/deployment/applet/security.html

关于java - 从 http 客户端获取 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19175658/

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