我对编程很陌生,并且在理解RESTful API的概念方面遇到了一些麻烦.我读过有关REST和RESTful API的文章.我已经查看了SO中已经提出的问题,但似乎无法更好地理解这个主题.
在我的网络编程类中,我正在使用套接字编程.任务中有两部分,A部分和B部分.
在A部分,我编写了一个响应GET和POST的服务器.服务器检索客户端请求的文件,或写入文件.(使用HTTP协议).
在B部分中,我将使用HTTP来实现RESTful应用程序.基本上它是一个消息服务器,能够处理GET,POST,PUT和DELETE.在这部分中,服务器将创建xml文件并与之交互.我理解这些方法是如何工作的.但我真正不明白的是以下内容:
为什么A部分服务器不是RESTful,而B部分是RESFTful?
我在互联网上搜索了很多时间,但是找不到与我的情况相符的任何东西.
我只想用TCP或UDP实现一个服务器/客户端应用程序,其中我的Android App(Xamarin)充当服务器,我的.NET应用程序充当客户端.由于我没有太多的应用程序开发经验和没有Xamarin的经验,我一直在寻找一个例子.我发现的只有:
http://www.codeproject.com/Articles/340714/Android-How-to-communicate-with-NET-application-vi
首先,这是相反的方式(服务器在.NET和客户端作为应用程序),另外它是为Android Studio所以我很难将这些东西翻译成Xamarin而没有错误.
请有人帮忙,并举例说明如何实现我的问题?
谢谢!
我正在运行一个应用程序,它需要一个泄漏内存的库.(不幸的是,这个propriotory软件没有替代品).因此,dynos超出其内存限制并发出错误R14(超出内存配额)错误.
有没有办法自动重启发出错误R14的dynos?
或者Heroku实际上会为我重新启动dynos,如果是的话大概是什么时候?(在文档中找不到任何内容,我从未注意到heroku关闭了我的dynos)
非常感谢你提前!
埃迪
我正在学习一个名为“Black Hat Python”的教程,并收到“请求的地址在其上下文中无效”错误。我是 Python IDE 版本:2.7.12 这是我的代码:
import socket
import threading
bind_ip = "184.168.237.1"
bind_port = 21
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((bind_ip,bind_port))
server.listen(5)
print "[*] Listening on %s:%d" % (bind_ip,bind_port)
def handle_client(client_socket):
request = client_socket.rev(1024)
print "[*] Recieved: %s" % request
client_socket.close()
while True:
client,addr = server.accept()
print "[*] Accepted connection from: %s:%d" % (addr[0],addr[1])
client_handler = threading.Thread(target=handle_client,args=(client,))
client_handler.start()
Run Code Online (Sandbox Code Playgroud)
这是我的错误:
Traceback (most recent call last):
File "C:/Python34/learning hacking.py", line 9, in <module>
server.bind((bind_ip,bind_port))
File "C:\Python27\lib\socket.py", line 228, in meth
return …Run Code Online (Sandbox Code Playgroud) 如何主持angular 2网站?
我是角度2的新手,我创建了一个没有后端的简单网站.
我想知道当我尝试直接打开index.html文件时,它会打开并显示错误.
但是在命令之后"npm start"它运行正常,它在计算机上运行本地服务器.
那么,如何在简单的托管网站上托管这个网站(不是专用服务器..!)?
我认为托管站点会自动找到index.html文件,但是这里有问题,index.html是没有"npm start"命令就启动的.
我可以在服务器上启动进程吗?
请指导我.
我正在搞乱节点,我正在尝试获取URL类的实例(因为那些方便的属性).喜欢:
const { URL } = require('url');
(...)
http.createServer((request,response) => {
let uri = new URL(request.url);
(...)
}
Run Code Online (Sandbox Code Playgroud)
但它失败了
TypeError [ERR_INVALID_URL]: Invalid URL: /
Run Code Online (Sandbox Code Playgroud)
这很有趣因为
const url = require('url');
url.parse();
Run Code Online (Sandbox Code Playgroud)
作品.所以我很好奇.我明白后面的方法比较旧.
我正在本地开发所以发送请求我在浏览器中使用localhost:8000.
如何使用该信息request实例化新的URL对象?
信息和我已经看过的东西:
node -v
v9.3.0
https://nodejs.org/api/url.html#url_class_url
https://stackoverflow.com/questions/44738065/uncaught-typeerror-url-is-not-a-constructor-using-whatwg-url-object-support-for
https://stackoverflow.com/questions/45047840/in-node-js-how-to-get-construct-url-string-from-whatwg-url-including-user-and-pa
https://stackoverflow.com/questions/47481784/does-url-parse-protect-against-in-a-url
https://stackoverflow.com/questions/17184791/node-js-url-parse-and-pathname-property
Run Code Online (Sandbox Code Playgroud) 我的客户通过Authorization标头中的令牌进行授权,每个请求都需要检查该令牌。如果没有这个头或者找不到对应的用户,我想返回HTTP代码Unauthorized,否则我想正常处理请求。
目前我有很多重复的代码,因为我正在每个请求处理程序中检查这个标头。该Actix的文档中的第一段表明,它是可能的halt request processing to return a response early。如何做到这一点?
由于我还没有找到实现此行为的示例,因此我尝试提出自己的中间件函数,但无法编译。
为了克服返回两种不同类型(ServiceResponse和Map)的问题,我已经对返回值进行了装箱,因此在如何有条件地返回不同类型的期货?不是问题。更重要的是,我不知道哪些类型具有哪些特征实现需要作为此wrap_fn函数的返回值。我现在拥有的那些不起作用。
App::new()
.wrap(Cors::new().allowed_origin("http://localhost:8080"))
.register_data(state.clone())
.service(
web::scope("/routing")
.wrap_fn(|req, srv| {
let unauth: Box<dyn IntoFuture<Item = ServiceResponse>> = Box::new(ServiceResponse::new(req.into_parts().0, HttpResponse::Unauthorized().finish()));
let auth_header = req.headers().get("Authorization");
match auth_header {
None => unauth,
Some(value) => {
let token = value.to_str().unwrap();
let mut users = state.users.lock().unwrap();
let user_state = users.iter_mut().find(|x| x.auth.token == token);
match user_state {
None => unauth,
Some(user) …Run Code Online (Sandbox Code Playgroud) 我得到了一个使用 emscripten 编译的 webassembly 模块。现在我正在尝试使用 expressjs 在网页中提供它。
我已经尝试按照这个要点来通过 webpack 包含 webassembly,包括我发现的一个修改,因为这个要点有点旧。
webpack 看起来像这样:
const path = require('path');
module.exports = {
optimization: {
mangleWasmImports: false
},
entry: './src/index.js',
output: {
path: path.resolve(__dirname, './dist/'),
filename: 'dynamic-graph.bundle.js'
},
target: "web",
module: {
rules: [
// Emscripten JS files define a global. With `exports-loader` we can
// load these files correctly (provided the global’s name is the same
// as the file name).
{
test: /fourd\.js$/,
loader: "exports-loader"
},
// wasm files …Run Code Online (Sandbox Code Playgroud) 用于使用 gunicorn 运行的烧瓶应用程序
$ pip install gunicorn
$ gunicorn --bind 0.0.0.0:8000 app:app
Run Code Online (Sandbox Code Playgroud)
出错
回溯(最近一次调用):文件“C:\Users\shubham\AppData\Local\Programs\Python\Python37\lib\runpy.py”,第 193 行,在 _run_module_as_main “ main ”,mod_spec)文件“C:\ Users\shubham\AppData\Local\Programs\Python\Python37\lib\runpy.py”,第 85 行,在run_code exec(code, run_globals) 文件“C:\Users\shubham\Desktop\Full_stack_developer\venv\Scripts\gunicorn .exe_主.py”,第 5 行,在文件“c:\users\shubham\desktop\full_stack_developer\venv\lib\site-packages\gunicorn\app\wsgiapp.py”中,第 9 行,来自 gunicorn.app.base 导入应用程序文件“c:\users\shubham\desktop\full_stack_developer\venv\lib\site-packages\gunicorn\app\base.py”,第 11 行,来自 gunicorn 导入 util 文件“c:\users\shubham\desktop\full_stack_developer \venv\lib\site-packages\gunicorn\util.py”,第 9 行,在 import fcntl ModuleNotFoundError: No module named 'fcntl'
我写了这个,但出现错误,我不知道如何解决
var http = require('http');
var clientHtml = require('fs').readFileSync('client.html');
var plainHttpServer = http.createServer(function (request, response) {
response.writeHead(200, { 'Content-Type': 'text/html' });
response.end(clientHtml);
}).listen(8080);
var files = require('fs');
var io = require('socket.io').listen(plainHttpServer);
io.set('origins', ['localhost:8080', '127.0.0.1:8080']);
Run Code Online (Sandbox Code Playgroud)
这个错误来了,我不知道如何解决,告诉我
var io = require('socket.io').listen(plainHttpServer);
^
TypeError: require(...).listen is not a function
Run Code Online (Sandbox Code Playgroud)