标签: http-post

如何从简单的 Ruby 服务器捕获 POST 数据

我有一个基本的 Ruby 服务器,我想侦听特定端口,读取传入的 POST 数据并执行等等...

我有这个:

require 'socket'               # Get sockets from stdlib

server = TCPServer.open(2000)  # Socket to listen on port 2000
loop {                         # Servers run forever
  client = server.accept       # Wait for a client to connect
  client.puts(Time.now.ctime)  # Send the time to the client
  client.puts "Closing the connection. Bye!"
  client.close                 # Disconnect from the client
}
Run Code Online (Sandbox Code Playgroud)

我将如何捕获 POST 数据?

谢谢你的帮助。

ruby http-post

5
推荐指数
2
解决办法
3521
查看次数

PHP - HTTP GET|PUT|POST 的原生常量

是否有在原生 php 语言中定义的“GET”、“POST”等常量,我已经尝试过:

HTTP_METH_GET
Run Code Online (Sandbox Code Playgroud)

等,
但没有成功

php constants http-get http-post httprequest

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

将 POST 变量添加到 Go test http 请求

我正在尝试将表单变量添加到 Go http 请求中。

这是我的 Go 测试的样子:

func sample_test(t *testing.T) {
    handler := &my_listener_class{}
    reader := strings.NewReader("number=2")
    req, _ := http.NewRequest("POST", "/my_url", reader)
    w := httptest.NewRecorder()
    handler.function_to_test(w, req)
    if w.Code != http.StatusOK {
        t.Errorf("Home page didn't return %v", http.StatusOK)
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是表单数据永远不会传递给我需要测试的函数。

另一个相关函数是:

func (listener *my_listener_class) function_to_test(writer http.ResponseWriter, request *http.Request) {
    ...
}
Run Code Online (Sandbox Code Playgroud)

我正在使用 Go 版本 go1.3.3 darwin/amd64。

testing unit-testing http-post go

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

取消“HttpClient”POST 请求

我正在使用HttpClient.PostAsync()我的 Windows Phone 8 应用上传图像。用户可以选择通过 UI 按钮取消此上传。

为了取消 POST 请求,我设置了一个CancellationToken. 但这不起作用。在取消请求之后,我仍然看到在我的代理中进行了上传,很明显该请求被忽略了。我的代码:

using (var content = new MultipartFormDataContent())
{
    var file = new StreamContent(stream);
    file .Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
    {
        FileName =  "filename.jpg",
    };
    file.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
    content.Add(file);

    await httpclient.PostAsync(new Uri("myurl", UriKind.Absolute), content,
        cancellationToken);
}
Run Code Online (Sandbox Code Playgroud)

另请注意,我有一CancellationTokenSource对CancellationToken。在用户点击取消按钮后,tokensource.Cancel()被调用。此外,我的测试用例中的图像从 1 到 2 MB(不是那么大)。

那么,有没有办法取消HttpClientPOST 请求?

c# httpclient http-post cancellation windows-phone-8

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

如何在 Jersey 客户端 HTTP POST 请求中发布原始 json 文本?

我想发出一个HTTP POST请求,它要求参数必须作为原始 JSON 文本传递,但我不知道如何使用 Jersey 客户端。
这是 API 规范(在 Postman Rest Client 中运行良好):(请看我的 Postman 的屏幕截图,URL、正文中的参数和 2 个标题是 Content-Type:application/json 和 Accept:application/json) 邮差客户端
这是我在 Jersey 中尝试过的:

JsonObject parameters = new JsonObject();
parameters.addProperty("centerId", centerId);
parameters.addProperty("studentId", studentId);

if (fromDate != null) {
    parameters.addProperty("fromDate", fromDate);
}
if (toDate != null) {
    parameters.addProperty("toDate", toDate);
}

Object response = client.target("http://localhost:8080/rest").path("student/calendar")
    .request(MediaType.APPLICATION_JSON).post(Entity.json(parameters), String.class);
Run Code Online (Sandbox Code Playgroud)

但没有任何效果。谁能建议在这种情况下处理泽西岛的正确方法是什么?谢谢你。

java json jersey http-post

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

php.ini 中的 max_input_vars 实际影响什么,什么是安全的高值?

我知道 php.ini 的值max_input_vars默认为 1000(我使用的是 5.6 版)。我的 POST 数据被截断了,所以我需要增加这个值。这确实解决了我的问题。在更改这些值时,我只是想了解它实际上具体影响了什么。

如果我向后端发送一组数据,这是否意味着它只能包含大约 1000 个元素?看起来我的表单总和没有达到 1000 个输入字段,所以我试图弄清楚这个数字是做什么用的。

我可以达到的安全高数是多少?10000会不会太高了?

php apache http-post

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

NodeJS Request Bearer

I can't seem to get a proper response using the request package with node. I have tried several different placements according to the documentation on npm but keep getting the same result.

"Invalid Access Token 401"

I've asked around the forums and they ensure me that the token I'm using is correct. Any help would be greatly appreciated!

const restify = require('restify');
const request = require('request');

var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, () => {
   console.log('%s listening …
Run Code Online (Sandbox Code Playgroud)

http-post node.js npm

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

如何使用httppost/rest-api从keycloak获取用户列表

我是keycloak 的新手,任何帮助都是可观的。我可以使用 keycloak api 获取用户详细信息列表,我想知道如何使用 http-post 获取它。

Keycloak kc = Keycloak.getInstance("url-path", "realm", "username", "password", "admin-cli");
Run Code Online (Sandbox Code Playgroud)

通过使用这个 keycloak 对象,我可以获得用户列表。但是,当我想通过使用 keycloak 提供的端点 url 使用 http-post 或 rest api 调用获取用户列表时,我无法根据令牌获取访问令牌,我只获取特定用户,我想要使​​用rest api的用户列表。

http-post keycloak-services

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

如何将数组数据作为 formdata angular 4 发送

我试图发布一组未发送到服务器的数据:

网络服务:

 deleteCategory() {
    return  this.http.post('http://www.demo/webapi/deletecategory', { 
        headers: {
          "Authorization": "Token " + this.token,
          "Content-Type": "application/x-www-form-urlencoded"
        },
        withCredentials: true
      }
      )
    }
Run Code Online (Sandbox Code Playgroud)

在 ts 文件中

onDelete() {
      this.userService.deleteCategory().subscribe(response => {
      this.selectedArray = [];
     for (var i = 0; i< this.selection._selected.length; i++){
     this.selectedArray.push(this.selection._selected[i].category_id) ;
     console.log(' selected value:', this.selectedArray);

     }
    })
      }
Run Code Online (Sandbox Code Playgroud)

在 html 中

<button class="btn-danger pull-right" (click)="onDelete()" type="button"  >Delete</button>
Run Code Online (Sandbox Code Playgroud)

http-post angular-http angular

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

spring boot 和 spring security 自定义登录页面和控制器

我想通过自定义控制器和登录页面更好地控制登录和注销。

我的 SecurityConfiguration 代码目前如下所示:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    private SpringDataJpaUserDetailsService userDetailsService;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .userDetailsService(this.userDetailsService)
                .passwordEncoder(Manager.PASSWORD_ENCODER);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
        .authorizeRequests()
            .antMatchers("/resources/**", "/built/**", "/main.css", "/login.css").permitAll() 
            .anyRequest().authenticated()
            .and()
        .formLogin()
            .loginPage("/login")
            .loginProcessingUrl("/loginSecure")
            .defaultSuccessUrl("/index", true)
            .permitAll()
            .usernameParameter("username").passwordParameter("password")
            .and()
        .csrf().disable()
        .logout()                                    
            .permitAll();
    }

}
Run Code Online (Sandbox Code Playgroud)

我的控制器中的登录配置:

@RequestMapping(value = "/login")
public String login() {
    return "login";
}
Run Code Online (Sandbox Code Playgroud)

我的控制器中的 loginSecure 映射:

@RequestMapping(value="/loginSecure", method = RequestMethod.POST)
    public String …
Run Code Online (Sandbox Code Playgroud)

java forms http-post spring-security spring-boot

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