Tag: httprequest

如何在java中处理阿拉伯语

我需要将一串阿拉伯值传递给HttpURL作为参数但在我说我打印消息之前它只显示问号 public void sendSms(SendSms object) throws MalformedURLException,ProtocolException,IOException { String message=new String(object.getMessage().getBytes(), “UTF-8”); System.out.println(message);//printing only question marks } 甚至当我发送消息作为url参数时,它不发送原始消息作为阿拉伯语发送问号。 public void sendSms(SendSms object) throws MalformedURLException, ProtocolException,IOException { String message=new String(object.getMessage().getBytes(), “UTF-8”); System.out.println(message); PrintStream out = new PrintStream(System.out, true, “UTF-8″); out.print(message); String charset=”UTF-8”; URL url = new URL(“http://62.215.226.164/fccsms_P.aspx”); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestProperty(“Accept-Charset”, charset); con.setRequestMethod(“POST”); //con.setRequestProperty(“User-Agent”, […]

在struts 2中上传video

我想在我的struts 2 Web应用程序中上传video。 为此,我使用文件上传拦截器 。 我的问题是,我能够成功上传图像和文本文件,但无法查看video和flash文件,文件参数在我的操作中没有得到初始化。 我是按照以下方式做的: struts.xml中的条目: image/png,image/gif,image/jpeg,image/pjpeg,image/jpg,video/x-ms-rmvb,video/x-ms-wmv,video/x-ms-avi, video/fli,video/x-fli,video/x-atomic3d-feature,video/gl,video/x-gl,video/x-isvideo,video/mpeg,video/x-motion-jpeg,video/quicktime,video/x-sgi-movie, video/x-mpeg,video/vnd.rn-realvideo,video/x-scm <!– text/plain –> 10485760 dssUploadContent dssUploadContent login.jsp 我在这做什么错,请告诉我。 谢谢。

BlackBerry上的HTTP Post请求

我正在尝试从我的BlackBerry OS <7.X应用程序发送一个json字符串到我的服务器。 我正在尝试使用HTTP Post请求。 到目前为止我所做的是: String httpURL = “http://ip_of_my_server/phpServer/receiver2.php/” + jsonString; try { HttpConnection httpConn; httpConn = (HttpConnection) Connector.open(httpURL + getConnectionString()); httpConn.setRequestMethod(HttpConnection.POST); httpConn.setRequestProperty(“Content-Type”, “application/json; charset=utf-8”); DataOutputStream _outStream = new DataOutputStream(httpConn.openDataOutputStream()); byte[] request_body = httpURL.getBytes(); for (int i = 0; i < request_body.length; i++) { _outStream.writeByte(request_body[i]); } DataInputStream _inputStream = new DataInputStream(httpConn.openInputStream()); StringBuffer _responseMessage = […]

使用Java发送HTTP Post Payload

我正在尝试连接到groovehark API,这是http请求 POST URL http://api.grooveshark.com/ws3.php?sig=f699614eba23b4b528cb830305a9fc77 POST payload {“method”:’addUserFavoriteSong”,’parameters”:{“songID”:30547543},”header”: {“wsKey”:’key”,”sessionID”:’df8fec35811a6b240808563d9f72fa2′}} 我的问题是如何通过Java发送此请求?

将变量从JSP传递给servlet

一直以来,当我在Google上搜索时,我收到了十二个在Stackoverflow中发布的关于将变量从JSP传递到servlet的答案。 但我想知道,我没有得到答案: How to pass a variable from JSP to a servlet class? Is it possible? How to pass a variable from JSP to a servlet class? Is it possible? 其实我正在做一个简单的PhoneBook应用程序。 在这里,我必须将联系人ID发送到servlet进行编辑和删除。 我怎样才能传递这个值? 我知道,我们可以使用request.setAttribute(key, value)将变量从servlet传递给JSP但是当我用它在JSP中设置变量并再次使用session.getAttribute(key )获取它时,结果为null。 神救救我。

如何将String转换为JsonObject

我正在使用httprequest将Json从Web变为字符串。 它可能很简单,但我似乎无法将此字符串转换为javax.json.JsonObject 。 我怎样才能做到这一点?

如何从Java中的HTTP请求中获取JSON对象

我现在正试图在Java线路中使用HTTP请求获取JSON对象。 我想知道如何在下面的电话中获得响应或JSON对象。 请告诉我。 (在这个程序中,我尝试获得维基百科类别的文章“纽约”。) String requestURL = “http://en.wikipedia.org/w/api.php?action=query&prop=categories&format=json&clshow=!hidden&cllimit=10&titles=” + words[i]; URL wikiRequest = new URL(requestURL); URLConnection connection = wikiRequest.openConnection(); connection.setDoOutput(true); /**** I’d like to get response here. ****/ JSONObject json = Util.parseJson(response);

如何用Java解析HTTP请求?

实现代理服务器时,我得到一个HTTP请求作为字符串,例如: GET http:// localhost:54321 / x HTTP / 1.1 主持人:localhost:54321 缓存控制:无缓存 是否有内置类来解析此请求?

Tomcat:getHeader(“Host”)与getServerName()

我有一个Tomcat应用程序,它是从多个域提供的。 以前的开发人员构建了一个返回应用程序URL的方法(见下文)。 在该方法中,它们请求服务器名称( request.getServerName() ),该名称适当地从httpd.conf文件返回ServerName 。 但是,我不希望这样。 我想要的是浏览器发送请求的主机名,即浏览器从哪个域访问应用程序。 我尝试了getHeader(“Host”) ,但仍然返回httpd.conf文件中设置的ServerName 。 而不是request.getServerName() ,我应该使用什么来获取浏览器发送请求的服务器名称? 例如: httpd.conf中的 ServerName: www.myserver.net 用户访问www.yourserver.net上的 Tomcat应用程序 我需要返回www.yourserver.net而 不是 www.myserver.net 。 request.getServerName()调用似乎只返回www.myserver.net /** * Convenience method to get the application’s URL based on request * variables. * * @param request the current request * @return URL to application */ public static String getAppURL(HttpServletRequest […]

如何在Java servlet容器上指定Http Request timeout参数

我试图了解在哪里可以为到达我的servlet(或我所有的servlet)的所有请求配置请求超时? 那是我认为的容器财产吗? 另外,这对不同的浏览器有何影响? 它们都符合容器规定的参数吗? 或者请求超时时间甚至不是我可以控制的,每个浏览器自己决定这个? (只是要清楚我不是在谈论会话超时)