标签: client

通用开源REST客户端?

我想要一个简单的客户端,它接受一些参数(方法,URL,参数),发出HTTP请求,并向我显示返回的结果.

浏览器显然可以轻松发送GET和POST请求,但我对DELETE和UPDATE没有好主意.

我在浏览器101中遗漏了什么,或者是否有一个常见的免费软件工具来做这件事?我见过其他线程为我提供了一个简单客户端的Java API,但这不是我想要的.

java rest client open-source http

12
推荐指数
3
解决办法
8917
查看次数

获取WCF的客户端IP地址,后期操作

我试图通过以下链接确定客户端的IP地址:http://www.danrigsby.com/blog/index.php/2008/05/21/get-the-clients-address-in-wcf/

在.Net 3.0中,没有可靠的方法来获取连接到WCF服务的客户端的地址.在.Net 3.5中引入了一个名为RemoteEndpointMessageProperty的新属性.此属性为您提供客户端连接进入服务的IP地址和端口.获取这些信息非常简单.只需通过RemoteEndpointMessageProperty.Name从当前OperationContext的IncomingMessageProperties中提取它,然后访问Address和Port属性.

> [ServiceContract] public interface IMyService {
>     [OperationContract]
>     string GetAddressAsString(); }
> 
> public class MyService : IMyService {
>     public string GetAddressAsString()
>     {
>         RemoteEndpointMessageProperty clientEndpoint =
>             OperationContext.Current.IncomingMessageProperties[
>             RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
> 
>         return String.Format(
>             "{0}:{1}",
>             clientEndpoint.Address, clientEndpoint.Port);
>     } } 
Run Code Online (Sandbox Code Playgroud)

注意事项:

  1. 此属性仅适用于http和tcp传输.在所有其他传输上,例如MSMQ和NamedPipes,此属性将不可用.
  2. 地址和端口由服务计算机的套接字或http.sys报告.因此,如果客户端通过VPN或其他修改地址的代理进入,则将表示该新地址而不是客户端的本地地址.这是可取和重要的,因为这是服务看到客户端的地址和端口,而不是客户端所看到的.这也意味着可能会有一些欺骗行为.客户端或服务器之间的某个客户端可能会欺骗地址.因此,除非添加一些其他自定义检查机制,否则不要使用地址或端口进行任何安全性决策.
  3. 如果您在服务上使用双工,那么不仅服务会为客户端填充此属性,而且客户端还将为该服务的每次调用填充此属性.

我有WebInvoke/Post和WebGet的operationContracts.当客户端请求是WebGet时,代码有效.但是当客户端请求是WebInvoke时,我将获得WCF主机IP.有解决方案吗 谢谢.

这是界面

[OperationContract]
[WebGet(UriTemplate = RestTemplate.hello_get)]
Stream hello_get();

[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = RestTemplate.hello_post)]
Stream hello_post();

// Code for …
Run Code Online (Sandbox Code Playgroud)

wcf client ip-address webinvoke

12
推荐指数
1
解决办法
8311
查看次数

Rails ActionController:request.remote_ip和request.remote_addr之间的区别

在ActionController源中,本地请求定义如下:

def local_request? #:doc:
    request.remote_addr == LOCALHOST && request.remote_ip == LOCALHOST
end
Run Code Online (Sandbox Code Playgroud)

在我的应用程序中,如果请求来自特定的IP范围,我想使用不同的逻辑.request.remote_addr和之间有什么区别request.remote_ip,我应该使用哪一个?

client ruby-on-rails ip-address request actioncontroller

12
推荐指数
2
解决办法
4694
查看次数

尝试将文件上传到JAX-RS(泽西岛)服务器

我正在尝试使用带有Jersey的multipart/form-data客户端上传文件和其他表单数据.我也使用Jersey上传到REST Web服务.这是服务器代码:

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public String create(@FormDataParam("file") InputStream file,
        @FormDataParam("file") FormDataContentDisposition fileInfo,
        @FormDataParam("name") String name,
        @FormDataParam("description") String description) {
    Ingredient ingredient = new Ingredient();
    ingredient.setName(name);
    ingredient.setDescription(description);
    ingredient.setImageName(fileInfo.getFileName());
    ingredient.setImagePath(context.getRealPath("/resources/uploads/"));
    // TODO save the file.
    try {
        JSONObject json = new JSONObject();
        try {
            ingredientService.create(ingredient);
        } catch (final InvalidParameterException ex) {
            logger.log(Level.INFO, ex.getMessage());
            json.put("result", false);
            json.put("error", ex.getMessage());
            return json.toString();
        } catch (final GoodDrinksException ex) {
            logger.log(Level.WARNING, null, ex);
            json.put("result", false);
            json.put("error", ex.getMessage());
            return json.toString();
        }
        json.put("ingredient", JsonUtil.ingredientToJSON(ingredient));
        return json.put("result", true).toString();
    } …
Run Code Online (Sandbox Code Playgroud)

java client file-upload jax-rs jersey

12
推荐指数
1
解决办法
5万
查看次数

从Android(作为客户端)发送TCP数据 - 没有数据被发送?

我正在尝试通过TCP将数据从我的Android应用程序发送到我的PC.

代码如下:

Socket socket = new Socket("10.0.78.75", 50505);   

OutputStream out = socket.getOutputStream();       
PrintWriter output = new PrintWriter(out);         

mStatusText.setText("Sending Data to PC");         
output.println("Hello from Android");              
mStatusText.setText("Data sent to PC");            

socket.close();                                    
mStatusText.setText("Socket closed");              
Run Code Online (Sandbox Code Playgroud)

在执行此操作时,我根本没有得到任何错误,但是,服务器应用程序(用C#编写)不会获得任何数据.它看到客户端连接到它,并看到数据正在发送,但是,数据字符串是空的......并且想到为什么会发生这种情况?

PS:服务器代码从以下站点复制,并已使用C#TCP客户端进行测试. http://www.switchonthecode.com/tutorials/csharp-tutorial-simple-threaded-tcp-server

sockets client android tcp communication

12
推荐指数
2
解决办法
4万
查看次数

Spring集成或Apache HTTP客户端

我有一个spring应用程序,它需要为某些数据调用基于REST的外部API调用.

API的数据格式是JSON.

我的问题是,以下哪个选项更好,重量更轻,可以进行外部api调用

  1. Spring集成(使用ws:outbound-gateway)

  2. Apache Commons HttpClient

请分享你的想法......

apache integration spring client http

12
推荐指数
3
解决办法
2万
查看次数

创建一个独立的Java websocket客户端端点?

我想用Java 创建一个websocket端点客户端(尽可能纯,没有框架),但实际上我发现的所有示例都只有Java中的服务器端点,而客户端是Javascript.任何人都可以指出一个好的客户示例,或提供一个?

java client websocket

12
推荐指数
2
解决办法
2万
查看次数

如何在java中实现TCP服务器和TCP客户端来传输文件

我已经实现了简单的TCP服务器和TCP客户端类,可以将消息从客户端发送到服务器,消息将在服务器端转换为大写,但是如何实现从服务器到客户端的传输文件以及从客户端上传文件到服务器.以下代码是我所拥有的.

TCPClient.java:

import java.io.*;
import java.net.*;

class TCPClient {
 public static void main(String args[]) throws Exception {
        String sentence;
        String modifiedSentence;
        BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
        Socket clientSocket = new Socket("127.0.0.1", 6789);
        DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
        BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        sentence = inFromUser.readLine();
        outToServer.writeBytes(sentence + "\n");
        modifiedSentence = inFromServer.readLine();
        System.out.println("FROM SERVER:" + modifiedSentence);
        clientSocket.close();
    }
}
Run Code Online (Sandbox Code Playgroud)

TCPServer.java:

import java.io.*;
import java.net.*;

class TCPServer {
    public static void main(String args[]) throws Exception {
        int firsttime …
Run Code Online (Sandbox Code Playgroud)

java client tcp

11
推荐指数
1
解决办法
7万
查看次数

Node.js可以在Chrome中使用其本机客户端运行客户端(即将发布)

谷歌Chrome的本机客户端即将发布.http://blog.chromium.org/2011/02/native-client-getting-ready-for-takeoff.html 这是否允许node.js在浏览器中运行,使分布式应用程序能够相互通信而不必通过服务器?

javascript client p2p distributed-computing node.js

11
推荐指数
2
解决办法
2万
查看次数

Python套接字服务器/客户端编程

所以我只是进入python并尝试了一些东西.首先,我正在创建一个服务器,它可以执行简单的操作,例如"GET"存储的文本,"存储"旧文本上的新文本,以及"TRANSLATE"的小写文本为大写.但我有几个问题.到目前为止,这是我的代码:

import socket

HOST = ''   # Symbolic name meaning the local host
PORT = 24069    # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'
try:
    s.bind((HOST, PORT))
except socket.error , msg:
    print 'Bind failed. Error code: ' + str(msg[0]) + 'Error message: ' + msg[1]
    sys.exit()
print 'Socket bind complete'
s.listen(1)
print 'Socket now listening'
while 1:
    conn, addr = s.accept()
    print 'Connected with ' + addr[0] + ':' + str(addr[1])
    data = conn.recv(1024)
    reply = 'OK...' …
Run Code Online (Sandbox Code Playgroud)

python sockets client

11
推荐指数
1
解决办法
5万
查看次数