我是网络开发的新手.我有Android应用程序使用HTTPServer托管一些网页.我正在使用Netty来解码/编码请求/响应.现在,我想在有人导航到我的网页时显示基本身份验证对话框.像这样的东西:
我可以得到一些指示吗?这是HTTP内置的功能,任何RFC?我需要编写一些java脚本吗?任何帮助都会很棒.
javascript httpwebrequest httpwebresponse httpserver http-status-code-401
我正在尝试开发REST服务net/http.
该服务接收包含所有输入参数的JSON结构.我想知道是否有更简单,更短的方式来实现以下内容:
func call(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
fmt.Printf("Error parsing request %s\n", err)
}
var buf []byte
buf = make([]byte, 256)
var n, err = r.Body.Read(buf)
var decoded map[string]interface{}
err = json.Unmarshal(buf[:n], &decoded)
if err != nil {
fmt.Printf("Error decoding json: %s\n", err)
}
var uid = decoded["uid"]
...
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,只需要提取第一个参数就需要很多行.有任何想法吗?
我建立了一个网站,它必须与服务器进行实时通信。实时是指如果用户对某个主题进行投票,则所有连接的客户端都必须看到新的投票平均值。
我已经尝试了一些方法,但是遇到了一个问题:如何创建一个套接字服务器和一个HTTP服务器,以使用Node.JS侦听同一端口?我在下面运行代码,但有这个异常:
错误:听
EADDRINUSE
这是我的服务器代码:
let port = 8080;
const httpServer = require('http'),
app = require('express')(),
socketServer = http.Server(app),
io = require('socket.io')(httpServer);
httpServer.createServer(function (req, res) {
console.log('http server created on 8080');
}).listen(port);
socketServer.listen(port, function(){
console.log('listening on 8080');
});
Run Code Online (Sandbox Code Playgroud)
提前致谢
我正在实现 html5 播放器。它类似于流式传输,但不是严格意义上的流式传输。
首先我试过了。使用媒体源扩展。但我无法执行寻求。我不知道字节偏移量。
所以我认为。如果您可以在浏览器中创建 http 服务器,我只能响应范围请求。
我可以使用javascript在浏览器中创建http服务器吗?它支持移动/PC 浏览器。它必须支持移动/PC 浏览器。
我的系统中有nodejs。我使用npm(npm install -g http-server)全局安装了“ http-server”。安装http-server之后,我尝试运行http-server,但是显示“无法将'http-server'识别为内部或外部命令,可操作程序或批处理文件。”
我已经加入"%AppData%\Roaming\npm;"中NODE_PATH和"C:\Program Files\nodejs\;/usr/local/share/npm/bin/;"的PATH。但是我仍然有同样的问题。
谁可以帮我这个事。
我尝试启动多个 http 服务器,侦听同一包中的不同端口。在我的测试 HandleFunc 函数中,我需要打印我们的主机和服务请求的 http 服务器的端口信息。我该怎么做呢?
这是我的示例代码:
package main
import (
"encoding/json"
"flag"
"log"
"net/http"
"os"
"github.com/dineshgowda24/lb/backendserver/config"
)
func main() {
c := flag.String("c", "config/config.json", "Please specify conf.json")
flag.Parse()
file, err := os.Open(*c)
if err != nil {
log.Fatal("Unable to open config file")
}
defer file.Close()
decoder := json.NewDecoder(file)
config := bconfig.BackendConfiguration{}
err = decoder.Decode(&config)
if err != nil {
log.Fatal("Unable to decode conf.json file")
}
http.HandleFunc("/", handle)
for _, s := range config.Servers {
log.Printf("Started server at : …Run Code Online (Sandbox Code Playgroud) 我将 NodeJS http 服务器超时设置为 10 秒:
const httpServer = require('http').createServer(app);
httpServer.timeout = 10 * 1000;
Run Code Online (Sandbox Code Playgroud)
当运行 20 秒超时时,对服务器的传入请求将在 10 秒后超时:
await new Promise(resolve => setTimeout(resolve, 20000));
Run Code Online (Sandbox Code Playgroud)
当后端请求花费 20 秒时,服务器也会按预期超时,例如:
http://httpstat.us/200?sleep=20000
Run Code Online (Sandbox Code Playgroud)
但运行无限循环时不会超时:
while(true) {}
Run Code Online (Sandbox Code Playgroud)
这是为什么?
我想用我的Java HttpServer进行一些SQL查询,但似乎HttpServer无法识别我提交到浏览器的链接中的特殊字符:
[1]: http://localhost:8001/test?query=SELECT * WHERE{ ?s rdf:type ?o. }
Run Code Online (Sandbox Code Playgroud)
我总是收到这样的回复:
400 Bad Request
URISyntaxException thrown
Run Code Online (Sandbox Code Playgroud)
这是我的服务器的代码:
public class SimpleHttpServer
{
public static void main(String[] args) throws Exception
{
dir = args[0];
HttpServer server = HttpServer.create(new InetSocketAddress(8001), 0);
server.createContext("/test", new MyHandler());
server.setExecutor(null);
server.start();
}
static class MyHandler implements HttpHandler {
public void handle(HttpExchange t) throws IOException {
String response ;
System.out.println(t.getRequestURI().getQuery().toString().replaceAll("query=", ""));
response = ExecuteHttpQuery.getInstance().httpQuery(t.getRequestURI().getQuery().toString().replaceAll("query=", "").toString(), dir) + "\n";
t.sendResponseHeaders(200, response.length());
OutputStream os = t.getResponseBody();
os.write(response.getBytes());
os.close();
}
}
} …Run Code Online (Sandbox Code Playgroud) 我是IHS的新手,我遇到了我需要重定向我主页的URL的 www.example.com/foo --> www.example.com/foo/bar问题,其中一些路径www.example.com/foo/somethingelse是正确的,我已经阅读了很多关于mod_rewrite的文章,讨论了很多更复杂的解决方案但是未能找到这样简单的解决方案.此外,我对这个正则表达式的事情感到非常困惑.
请帮忙,谢谢.
我正在使用golang创建一个简单的http服务器.我有两个问题,一个是更理论的,另一个是关于真实的程序.
我创建一个服务器并使用s.ListenAndServe()来处理请求.尽管我理解同时提供的请求.我使用一个简单的处理程序来检查它:
func ServeHTTP(rw http.ResponseWriter, request *http.Request) {
fmt.Println("1")
time.Sleep(1 * time.Second) //Phase 2 delete this line
fmt.Fprintln(rw, "Hello, world.")
fmt.Println("2")
}
Run Code Online (Sandbox Code Playgroud)
我看到,如果我发送了几个请求,我会看到所有"1"出现,并且只有在第二个出现"2"之后.但是如果我删除了Sleep行,我会看到该程序在完成前一个请求之前从未启动过请求(输出为1 2 1 2 1 2 ...).所以我不明白,如果他们是并发或不是真的.如果他们是我希望看到一些混乱的印刷品......
在真正的处理程序中,我将请求发送到另一个服务器并将答案返回给用户(对请求和答案进行了一些更改,但在想法中它是一种代理).所有这些当然需要时间和从可以看到的内容(通过向处理程序添加一些打印),请求被逐个处理,它们之间没有并发(我的打印显示请求开始,执行所有步骤,结束,然后才看到一个新的开始......).我该怎么做才能让它们真正并发?
将处理程序函数设置为goroutine会产生错误,请求的主体已经关闭.此外,如果已经并发添加更多goroutines将使事情变得更糟.
谢谢!
httpserver ×10
go ×3
javascript ×3
node.js ×3
apache ×1
browser ×1
concurrency ×1
go-http ×1
http ×1
httprequest ×1
java ×1
json ×1
mod-rewrite ×1
npm ×1
npm-install ×1
redirect ×1
rest ×1
socket.io ×1
sockets ×1