我有一个基本的 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 数据?
谢谢你的帮助。
是否有在原生 php 语言中定义的“GET”、“POST”等常量,我已经尝试过:
HTTP_METH_GET
Run Code Online (Sandbox Code Playgroud)
等,
但没有成功
我正在尝试将表单变量添加到 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。
我正在使用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 请求?
我想发出一个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)
但没有任何效果。谁能建议在这种情况下处理泽西岛的正确方法是什么?谢谢你。
我知道 php.ini 的值max_input_vars默认为 1000(我使用的是 5.6 版)。我的 POST 数据被截断了,所以我需要增加这个值。这确实解决了我的问题。在更改这些值时,我只是想了解它实际上具体影响了什么。
如果我向后端发送一组数据,这是否意味着它只能包含大约 1000 个元素?看起来我的表单总和没有达到 1000 个输入字段,所以我试图弄清楚这个数字是做什么用的。
我可以达到的安全高数是多少?10000会不会太高了?
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) 我是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的用户列表。
我试图发布一组未发送到服务器的数据:
网络服务:
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) 我想通过自定义控制器和登录页面更好地控制登录和注销。
我的 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) http-post ×10
java ×2
php ×2
angular ×1
angular-http ×1
apache ×1
c# ×1
cancellation ×1
constants ×1
forms ×1
go ×1
http-get ×1
httpclient ×1
httprequest ×1
jersey ×1
json ×1
node.js ×1
npm ×1
ruby ×1
spring-boot ×1
testing ×1
unit-testing ×1