Tag: post

在Spring RESTful服务中生成和使用自定义JSON对象

我有一些JSON对象比我拥有的java对象的JSON表示更复杂。 我有构建这些JSON对象的方法,我想直接返回并使用它们。 我使用org.json库来构建我的JSON。 我可以通过将JSON对象作为String返回来获得GET方法。 这是正确的方法吗? @RequestMapping(value = “/getjson”, method = RequestMethod.GET, produces=”application/json”) @ResponseBody public String getJson() { JSONObject json = new JSONObject(); JSONObject subJson = new JSONObject(); subJson .put(“key”, “value”); json.put(“key”, subJson); return json.toString(); } 现在我想知道如何使用JSON对象? 作为字符串并将其转换为JSON对象? @RequestMapping(value = “/post”, method = RequestMethod.POST, produces=”application/json”, consumes=”application/json”) @ResponseBody public String post(@RequestBody String json) { JSONObject obj = […]

Spring,不支持请求方法’POST’

首先要道歉请问这个反复的问题.. 实际上在我的春季应用程序中我有user.jsp和professional.jsp 这是我的User.jsp: 这是我的professional.jsp: Position Location Description 这是我的Controller类: @Controller @RequestMapping(value = “profile”) public class UserProfileController { @Autowired private UserService userService; @Autowired private SessionData sessionData; @RequestMapping(value = “user”, method = RequestMethod.GET) public String user(Model model) throws Exception { model.addAttribute(“PROFESSIONAL”, new UserProfessionalForm()); model.addAttribute(“EDUCATIONAL”, new UserEducationalForm()); model.addAttribute(“AWARDS”, new UserAwardsForm()); return “profile/user”; } @RequestMapping(value = “proffessional”, method = RequestMethod.POST) […]

常见的HTTP客户端和代理

我正在使用apache的常见httpclient库。 是否可以通过代理发出HTTP请求? 更具体地说,我需要使用代理列表来处理multithreadingPOST请求(现在我正在使用单线程GET请求进行测试)。 我试过用: httpclient.getHostConfiguration().setProxy(“67.177.104.230”, 58720); 我得到该代码的错误: 21.03.2012. 20:49:17 org.apache.commons.httpclient.HttpMethodDirector executeWithRetry INFO: I/O exception (java.net.ConnectException) caught when processing request: Connection refused: connect 21.03.2012. 20:49:17 org.apache.commons.httpclient.HttpMethodDirector executeWithRetry INFO: Retrying request 21.03.2012. 20:49:19 org.apache.commons.httpclient.HttpMethodDirector executeWithRetry INFO: I/O exception (java.net.ConnectException) caught when processing request: Connection refused: connect 21.03.2012. 20:49:19 org.apache.commons.httpclient.HttpMethodDirector executeWithRetry INFO: Retrying request 21.03.2012. 20:49:21 org.apache.commons.httpclient.HttpMethodDirector executeWithRetry […]

如何使用java访问github graphql API

我需要访问github graphql API来获取有关某个存储库的一些数据。 以下curl命令工作正常 curl -i -H “Authorization: bearer myGithubToken” -X POST -d ‘{“query”: “query { repository(owner: \”wso2-extensions\”, name: \”identity-inbound-auth-oauth\”) { object(expression:\”83253ce50f189db30c54f13afa5d99021e2d7ece\”) { … on Commit { blame(path: \”components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/authz/OAuth2AuthzEndpoint.java\”) { ranges { startingLine endingLine age commit { message url history(first: 2) { edges { node { message url } } } author { name email […]

将String数组作为POST传递给PHP

我试图将一个字符串数组作为POST数据传递给PHP脚本但不确定该怎么做。 这是我到目前为止执行PHP脚本的代码: 我试图传递数组的地方: nameValuePairs.add(new BasicNameValuePair(“message”,message)); String [] devices = {device1,device2,device3}; nameValuePairs.add(new BasicNameValuePair(“devices”, devices));// <– Can't pass String[] to BasicNameValuePair callPHPScript("notify_devices", nameValuePairs); 调用PHP脚本: public String callPHPScript(String scriptName, List parameters) { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(“http://localhost/” + scriptName); String line = “”; StringBuilder stringBuilder = new StringBuilder(); try { post.setEntity(new UrlEncodedFormEntity(parameters)); HttpResponse […]

如何使用Jsoup将数据发布到网站

我试图将数据发布到网站,使用Jsoup登录网站,但它无法正常工作? 我正在尝试代码 Document docs = Jsoup.connect(“http://some.com/login”) .data(“cmd”, “login”,”username”, “xxxx”,”password”, “yyyyy”) .referrer(“http://some.com/login/”).post(); 这里是在pagesource中提供正常的登录页面 我也尝试过代码 Document docs = (Document) Jsoup.connect(“http://some.com/login”) .data(“cmd”, “login”,”username”, “xxxx”,”password”, “yyyyy”) .referrer(“http://some.com/login/”).method(Method.POST).execute().parse(); 这里也是在pagesource中再次登录的正常页面。 任何有关相同的建议将受到高度赞赏! 谢谢….

如何使用JSoup发布文件?

我使用JSoup使用以下代码发布值: Document document = Jsoup.connect(“http://www……com/….php”) .data(“user”,”user”,”password”,”12345″,”email”,”info@tutorialswindow.com”) .method(Method.POST) .execute() .parse(); 现在我也想提交一份文件。 就像带有文件字段的表单一样。 这可能吗 ? 如果比怎么样?

cURL和HttpURLConnection – 发布JSON数据

如何使用HttpURLConnection发布JSON数据? 我正在尝试这个: HttpURLConnection httpcon = (HttpURLConnection) ((new URL(“a url”).openConnection())); httpcon.setDoOutput(true); httpcon.setRequestProperty(“Content-Type”, “application/json”); httpcon.setRequestProperty(“Accept”, “application/json”); httpcon.setRequestMethod(“POST”); httpcon.connect(); StringReader reader = new StringReader(“{‘value’: 7.5}”); OutputStream os = httpcon.getOutputStream(); char[] buffer = new char[4096]; int bytes_read; while((bytes_read = reader.read(buffer)) != -1) { os.write(buffer, 0, bytes_read);// I am getting compilation error here } os.close(); 我在第14行遇到编译错误。 cURL请求是: curl -H “Accept: […]

使用Java将文件上载和POST文件到PHP页面

我需要一种方法来上传文件并将其发布到php页面… 我的php页面是: <?php $maxsize = 10485760; $array_estensioni_ammesse=array('.tmp'); $uploaddir = 'uploads/'; if (is_uploaded_file($_FILES['file']['tmp_name'])) { if($_FILES['file']['size'] 我在我的桌面应用程序中使用这个java代码: HttpURLConnection httpUrlConnection = (HttpURLConnection)new URL(“http://www.mypage.org/upload.php”).openConnection(); httpUrlConnection.setDoOutput(true); httpUrlConnection.setRequestMethod(“POST”); OutputStream os = httpUrlConnection.getOutputStream(); Thread.sleep(1000); BufferedInputStream fis = new BufferedInputStream(new FileInputStream(“tmpfile.tmp”)); for (int i = 0; i < totalByte; i++) { os.write(fis.read()); byteTrasferred = i + 1; } os.close(); BufferedReader in = new […]

使用response.sendRedirect()传递隐藏参数

我如何传递隐藏的参数? 我想调用一个页面(test.jsp),但也传递2个隐藏参数,如post。 response.sendRedirect(“/content/test.jsp”);