http

using sockets to fetch a webpage with java

霸气de小男生 提交于 2021-02-08 10:13:07
问题 I'd like to fetch a webpage, just fetching the data (not parsing or rendering anything), just catch the data returned after a http request. I'm trying to do this using the high-level Class Socket of the JavaRuntime Library. I wonder if this is possible since I'm not at ease figuring out the beneath layer used for this two-point communication or I don't know if the trouble is coming from my own system. . Here's what my code is doing: 1) setting the socket. this.socket = new Socket( "www

How to get the requested file name in BaseHTTPServer in python?

允我心安 提交于 2021-02-08 09:10:40
问题 I'm writing an HTTP server in Python and I need to get the name of the requested file from the sent request in order to send from from the server Here is my code: from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer import os.path from os import curdir, sep PortNum = 8080 class myHandler(BaseHTTPRequestHandler): #Handler for the GET requests def do_GET(self): if self.path=="/": print os.path.splitext(self.path)[0] print self.path print "my code" self.path="/index_example3.html" try:

How to get the requested file name in BaseHTTPServer in python?

喜你入骨 提交于 2021-02-08 09:09:33
问题 I'm writing an HTTP server in Python and I need to get the name of the requested file from the sent request in order to send from from the server Here is my code: from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer import os.path from os import curdir, sep PortNum = 8080 class myHandler(BaseHTTPRequestHandler): #Handler for the GET requests def do_GET(self): if self.path=="/": print os.path.splitext(self.path)[0] print self.path print "my code" self.path="/index_example3.html" try:

Send image over http via socat bash webserver

℡╲_俬逩灬. 提交于 2021-02-08 08:59:48
问题 I am trying to write a webserver in bash using socat. I am having trouble serving image requests. I'm opening the socat listening connection like so: socat -T 30 -d -d TCP-L:$LISTENIP,reuseaddr,fork,crlf SYSTEM:"$0 \"docroot=$DOCROOT\"" I'm serving the image with the following, where $1 is the docroot and $2 is the image file name. function serve_png { if [ -e $1$2 ] then SIZE=`stat -c '%s' $1$2` echo -ne "HTTP/1.1 200 OK\nContent-type: image/png\nContent-length: $SIZE\n\n" cat $1$2 else echo

Browser accepts “classic” js script-tag, but not ES6 modules — MIME error w/ Node http server

一个人想着一个人 提交于 2021-02-08 08:42:12
问题 I want to play with ES6 modules, so I decided on using Node as a simple web server to avoid all CORS related errors I first encountered when doing it locally. Now I get MIME type related errors in the browser which I can't quite grasp. Here is my server.js file: const http = require('http'), url = require('url'), fs = require('fs'); http.createServer((req, res) => { const q = url.parse(req.url, true), filename = "." + q.pathname; fs.readFile(filename, (err, data) => { if (err) { res.writeHead

Parsing data from a network stream?

[亡魂溺海] 提交于 2021-02-08 07:49:24
问题 Recently I started working with sockets. I realized that when reading from a network stream, you can not know how much data is coming in. So either you know in advance how many bytes have to be recieved or you know which bytes . Since I am currently trying to implement a C# WebSocket server I need to process HTTP requests. A HTTP request can have arbitrary length, so knowing in advance how many bytes is out of the question. But a HTTP request always has a certain format. It starts with the

Parsing data from a network stream?

醉酒当歌 提交于 2021-02-08 07:47:05
问题 Recently I started working with sockets. I realized that when reading from a network stream, you can not know how much data is coming in. So either you know in advance how many bytes have to be recieved or you know which bytes . Since I am currently trying to implement a C# WebSocket server I need to process HTTP requests. A HTTP request can have arbitrary length, so knowing in advance how many bytes is out of the question. But a HTTP request always has a certain format. It starts with the

Create reusable http request Node.js function

隐身守侯 提交于 2021-02-08 06:51:35
问题 I'm trying to creating a script to trigger an IFTTT notification. What I got working so far is: var http = require('http') var body = JSON.stringify({ value1: "Temp Humid Sensor", value2: "Error", value3: "reading measurements" }) var sendIftttTNotification = new http.ClientRequest({ hostname: "maker.ifttt.com", port: 80, path: "/trigger/th01_sensor_error/with/key/KEY", method: "POST", headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(body) } })

Create reusable http request Node.js function

做~自己de王妃 提交于 2021-02-08 06:51:18
问题 I'm trying to creating a script to trigger an IFTTT notification. What I got working so far is: var http = require('http') var body = JSON.stringify({ value1: "Temp Humid Sensor", value2: "Error", value3: "reading measurements" }) var sendIftttTNotification = new http.ClientRequest({ hostname: "maker.ifttt.com", port: 80, path: "/trigger/th01_sensor_error/with/key/KEY", method: "POST", headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(body) } })

Cross domain HTTP requests

喜夏-厌秋 提交于 2021-02-08 06:33:08
问题 I was trying to send an HTTP POST request with certain parameters to a third party API which would return data. I was trying to it to work but was having issues. As part of my research into resolving the problem I started to read about cross domain HTTP requests.There were site after site on how to perform cross domain HTTP requests and why some methods were good and others bad. However, it was all written in a way that suggested that cross domain requests weren't the 'done' thing. Now,