Posts

Showing posts with the label http

HTTP in Java socket

HTTP in Java socket I want to send a JSON to an already written server (not from me). My problem is that I have an HTTP problem and need to convert it to HTTP. Server message: 2018-06-29 20:02:30.532:WARN:oejh.HttpParser:qtp245475541-15: badMessage: 400 No URI for HttpChannelOverHttp@2bb4ec27{r=0,c=false,a=IDLE,uri=} 2018-06-29 20:03:24.206:WARN:oejh.HttpParser:qtp245475541-18: badMessage: 400 No URI for HttpChannelOverHttp@866a0c9{r=0,c=false,a=IDLE,uri=} Code: public class client { public static void main(String args) { JsonObject js = new JsonObject(); js.addProperty("action","auth"); js.addProperty("type","android"); js.addProperty("token","lalalalalalalalala"); try { Socket ss = new Socket("localhost",3000); PrintWriter out = new PrintWriter(ss.getOutputStream(), true); BufferedReader in = ...

laravel redirect back to post route, i get MethodNotAllowedHttpException

laravel redirect back to post route, i get MethodNotAllowedHttpException At first on a get request i show a form, on submitting it, it goes to a post url does some working in the controller and then returns another view which has a form. after submitting this form i validate some things and if the validation fails i want to redirect back with some errors but unfortunately laravel isn't allowing me to redirect back to a post method. Is there any way i can accomplish this? i have seen this answer on laracast https://laracasts.com/discuss/channels/laravel/redirect-back-to-post-route-i-get-methodnotallowed-exception but i couldn't grasp the recommendation these are my routes in the order described above. Route::get('/purchasePacks', 'masterDealerController@purchasePacks')->name('purchasePacks'); Route::post('/confirmPuchasedPacks','masterDealerController@confirmPuchasedPacks'); Route::post('/storeOrder','masterDealerCont...

Node.js Streams: Is there a way to convert or wrap a fs write stream to a Transform stream?

Node.js Streams: Is there a way to convert or wrap a fs write stream to a Transform stream? With a node http server I'm trying to pipe the request read stream to the response write stream with some intermediary transforms, one of which is a file system write. The pipeline looks like this with non pertinent code removed for simplicity: function handler (req, res) { req.pipe(jsonParse()) .pipe(addTimeStamp()) .pipe(jsonStringify()) .pipe(saveToFs('saved.json')) .pipe(res); } The custom Transform streams are pretty straight forward, but I have no elegant way of writing saveToFs . It looks like this: saveToFs function saveToFs (filename) { const write$ = fs.createWriteStream(filename); write$.on('open', () => console.log('opened')); write$.on('close', () => console.log('closed')); const T = new Transform(); T._transform = function (chunk, encoding, cb) { write$.write(chunk); cb(null, chunk); } ret...