Tag: http

REALM术语在安全性方面的确切用途是什么?

术语REALM在安全性方面存在过载和混淆,这个术语在安全性方面的确切用途是什么?

将图像发布到Tumblr API

所以我正在编写一个小型Java应用程序,使用他们提供的API将图像目录转储到用户的tumblr博客中: http : //www.tumblr.com/docs/en/api 我已经发布明文了,但现在我需要找出如何在POST中发送图像文件。 我的代码目前正在返回403禁止错误,我尝试的其他所有内容都给我一个错误的请求错误。 如果可以的话,我宁愿不必使用外部库。 这是我的ImagePost类: import java.io.*; import java.net.*; public class ImagePost { String data = null; String enc = “UTF-8”; String type; File img; byte[] bytes; FileReader reader; ByteArrayOutputStream bytesOut; public ImagePost(String imgPath, String caption, String tags) throws IOException { //Construct data type = “photo”; img = new File(imgPath); bytes = […]

Java HTTP Post Applet服务器 – 内部生成的Image

我在applet中使用J2D创建了一个BufferedImage。 我想使用HTTP Post @ http:// localhost:3001 / upload / file上传这个BufferedImage。 编辑:我有一个ROR服务器处理服务器的东西,我正在寻找客户端的Java代码。 我能找到的所有例子都涉及上传文件。 有谁知道如何上传BufferedImage? 干杯, slotishtype

将PayPal curl请求转换为Java中的http请求

在PayPal网站上,所有示例调用都是使用curl完成的。 在Linux下使用CURL很容易重复,但我想使用Java来进行这些调用。 例如,假设有电话: curl -v https://api.sandbox.paypal.com/v1/payments/payment \ -H ‘Content-Type: application/json’ \ -H ‘Authorization: Bearer ‘ \ -d ‘{ “intent”:”sale”, “redirect_urls”:{ “return_url”:”http://example.com/your_redirect_url.html”, “cancel_url”:”http://example.com/your_cancel_url.html” }, “payer”:{ “payment_method”:”paypal” }, “transactions”:[ { “amount”:{ “total”:”7.47″, “currency”:”USD” } } ] }’ 假设我具有必须设置的的值,我如何将之前的字符串转换为http请求以使用Java和没有CURL从PayPal获得答案? 现在我对URL的HttpURLConnection执行了以下操作: private HttpURLConnection createPOSTHttpURLConnection(final URL url) throws IOException { final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(“POST”); connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); […]

URL中的文件名不包含文件名后缀

我需要从URL下载文件,除了我不知道文件的类型和我使用的URL在其末尾没有/random.file所以我无法解析该URL的URL文件名。 目前我正在使用Android下载管理器,它运行很好,意味着我没有处理下载,但我无论如何都看不到它下载的文件中的文件名。 如果我在Firefox中加载相同的URL,例如它询问’下载文件:Nameoffile.extension’。 在下载文件之前,有没有办法让我复制此行为并获取文件名?

玩2.5:在自定义http动作中获取响应体

我正在尝试使用Play 2.5.0 Java创建自定义http操作( https://playframework.com/documentation/2.5.x/JavaActionsComposition )来记录请求和响应主体。 这是我到目前为止所得到的: public class Log extends play.mvc.Action.Simple { public CompletionStage call(Http.Context ctx) { CompletionStage response = delegate.call(ctx); //request body is fine System.out.println(ctx.request().body().asText()) //how to get response body string here while also not sabotaging http response flow of the framework? //my guess is it should be somehow possible to access it below? […]

能够保持活动的HTTP服务器

我正在尝试用Java创建一个能够提供保持连接的http服务器。 我正在使用com.sun.net.httpserver.HttpServer类。 import java.io.IOException; import java.io.OutputStream; import java.net.InetSocketAddress; import com.sun.net.httpserver.Headers; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpServer; public class httpHandler implements HttpHandler { private String resp = “”; private OutputStream os = null; public void handle(HttpExchange t) throws IOException { System.out.println(“Handling message…”); java.io.InputStream is = t.getRequestBody(); System.out.println(“Got request body. Reading request body…”); byte[] b = new […]

如何控制SSLContext范围

如果我使用以下代码,因为我想,例如,更改证书的validation方式。 trm =一些信任经理 SSLContext sc = SSLContext.getInstance(“SSL”); sc.init(null, new TrustManager[] { trm }, null); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); 然后,这将为将来创建的所有https连接设置SSLContext,而不管是什么线程。 控制范围的最简洁方法是什么,以便我只为我想要的那些电话设置它?

缩略图上传YouTube API v3失败

YouTube API v3的记录非常糟糕。 我已经多次报告了很多错误,但没有人做出反应。 我仍然需要使用此API上传缩略图。 该指南指出: POST https://www.googleapis.com/youtube/v3/thumbnails/set 认证范围: https://www.googleapis.com/auth/youtubepartner https://www.googleapis.com/auth/youtube.upload https://www.googleapis.com/auth/youtube 参数: videoId:string videoId参数指定要为其提供自定义video缩略图的YouTubevideoID。 首先 – url错了 。 它必须是https://www.googleapis.com/upload/youtube/v3/thumbnails/set 。 现在关注代码,它使用Unirest : final HttpResponse response = Unirest.post(“https://www.googleapis.com/upload/youtube/v3/thumbnails/set”) .header(“Content-Type”, “application/octet-stream”) .header(“Authorization”, accountService.getAuthentication(account).getHeader()) .field(“videoId”, videoid) .field(“thumbnail”, thumbnail) .asString(); 收到的答复: { “error”: { “errors”: [ { “domain”: “global”, “reason”: “required”, “message”: “Required parameter: videoId”, “locationType”: “parameter”, “location”: […]

为什么这个简单的SOAP客户端不工作(org.apache.http)?

我想将一个XML文件作为请求发送到SOAP服务器。 这是我的代码:( 使用org.apache.http从使用SOAP操作发送HTTP Post请求进行了修改) import org.apache.http.client.*; import org.apache.http.client.methods.*; import org.apache.http.impl.client.*; import org.apache.http.entity.StringEntity; import org.apache.http.protocol.HTTP; import org.apache.http.HttpResponse; import java.net.URI; public static void req() { try { HttpClient httpclient = new DefaultHttpClient(); String body=”xml here”; String bodyLength=new Integer(body.length()).toString(); URI uri=new URI(“http://1.1.1.1:100/Service”); HttpPost httpPost = new HttpPost(uri); httpPost.setHeader( “SOAPAction”, “MonitoringService” ); httpPost.setHeader(“Content-Type”, “text/xml;charset=UTF-8”); StringEntity entity = new StringEntity(body, […]