如何使用Apache HttpClient来发布JSON请求?(How to POST JSON request using Apache HttpClient?)
我有如下的东西:
final String url = "http://example.com"; final HttpClient httpClient = new HttpClient(); final PostMethod postMethod = new PostMethod(url); postMethod.addRequestHeader("Content-Type", "application/json"); postMethod.addParameters(new NameValuePair[]{ new NameValuePair("name", "value) }); httpClient.executeMethod(httpMethod); postMethod.getResponseBodyAsStream(); postMethod.releaseConnection();
它不断回来与一个500.服务提供商说我需要发送JSON。 如何使用Apache HttpClient 3.1+?
I have something like the following:
final String url = "http://example.com"; final HttpClient httpClient = new HttpClient(); final PostMethod postMethod = new PostMethod(url); postMethod.addRequestHeader("Content-Type", "application/json"); postMethod.addParameters(new NameValuePair[]{ new NameValuePair("name", "value) }); httpClient.executeMethod(httpMethod); postMethod.getResponseBodyAsStream(); postMethod.releaseConnection();
It keeps coming back with a 500. The service provider says I need to send JSON. How is that done with Apache HttpClient 3.1+?
原文:https://stackoverflow.com/questions/12059278
最满意答案
你可以做相反的你想做的事情。 单击包资源管理
Filters...
右侧的白色箭头,选择Filters...
然后使用通配符键入表达式。 Eclipse 不会显示与此模式匹配的资源。您可以使用快捷键Ctrl + Shift + T或通常使用Ctrl + Shift + R搜索文件中的课程。 您可以按照与过滤器相同的方式指定模式。
You can do the opposite of what you want to do. Click on the white arrow on the right of the package explorer, select
Filters...
and type an expression with wildcards. Eclipse will not show the resources matching this pattern.You can search for types in your workspace with the shortcut Ctrl+Shift+T or for files in general with Ctrl+Shift+R. You can specify a pattern in the same way you can do for filters.
相关问答
更多-
嗯......看起来我们都有这个问题。 你可以使用这个插件来做到这一点,更多... 对不起自己的广告......但我认为这是你正在寻找的! Hmmm... Looks like we all have this problem. You can use this plugin to do exactly that and a bit more... Sorry for self advertising... But I think this is what you are looking for!
-
在Eclipse中,在包资源管理器中,可以按名称查找文件吗?(In Eclipse, in the package explorer, can I find files by name?)[2023-04-19]
你可以做相反的你想做的事情。 单击包资源管理Filters...右侧的白色箭头,选择Filters...然后使用通配符键入表达式。 Eclipse 不会显示与此模式匹配的资源。 您可以使用快捷键Ctrl + Shift + T或通常使用Ctrl + Shift + R搜索文件中的课程。 您可以按照与过滤器相同的方式指定模式。 You can do the opposite of what you want to do. Click on the white arrow on the right of the ... -
Eclipse - 如何更改包资源管理器的字体颜色?(Eclipse - How do you change the font color of package explorer?)[2022-03-08]
您无法单独更改包浏览器颜色。 但你可以尝试在eclipse中使用的不同主题。 打开eclipse首选项 一般 - >外观 - >主题 You can't change the package explorer color alone. But you can try different themes which are available in eclipse. Open eclipse preferences General -> Appearance -> Theme -
检查XML验证是否过时。 右键单击项目Properties-> Validation-> XML Syntax或尝试Window-> Preferences-> Xml-> Xml Files-> Validation I've found this tutorial. Apparently, the xml validation process has to be triggered manually from context menu and is not part of the project bui ...
-
这意味着此文件夹位于工作空间路径中。 It means this folder is in a workspace path.
-
如何在Eclipse Package Explorer中显示Javadoc文件?(How do I make Javadoc files show in Eclipse Package Explorer?)[2022-12-17]
我认为问题是生成Javadoc文件后的目标文件夹/目录。 我遇到了同样的问题,并发现(最后)Javadocs被发送到一个不同于我的包文件所在的文件夹。他们去了我认为也拥有我所有代码的工作区文件夹,但代码却变成了不同的库。 也许尝试查找代码的位置,然后查看生成的Javadocs是否在生成它们时在其他地方着陆。 如果是这种情况,则修复是重新生成并发送到代码的目录。 这样,Package Explorer应该能够找到并显示它们。 希望这可以帮助! I think that the problem is the d ... -
Package explorer只允许您查看在编译代码时已经处理过的jar。 因此,在普通的Java项目中,这将是'Referenced Libraries'部分和'JRE System Library'中的jar。 对于插件,还包括“Plug-in Dependencies”和“External Plug-ins”。 您可以暂时将库添加到项目的类路径中,以便查看内容。 Package explorer will only let you look in jars which have been proce ...
-
不,但在导航器视图中。 No, but in the Navigator view.
-
Eclipse和Mylyn:如何在资源管理器中禁用灰色文件?(Eclipse and Mylyn : how to disable grey files in the explorer?)[2023-07-10]
灰色表示资源对给定任务的上下文不太感兴趣。 您可以从workbench preferences / General / Appearange / Label Decorators / Task Context Decorator中禁用此装饰器。 Gray color indicates that resource has lesser interest in context of a given task. You can disable this decorator from workbench pref ... -
您可以从Menu Contributions维基页面开始。 它有大量的例子。 You can start at Menu Contributions wiki page. It has extensive list of examples.