HTTP POST

Hi I´m trying to do a HTTP POST to the event store with this code:

<%@ page language=“java” contentType=“text/html; charset=ISO-8859-1”
pageEncoding=“ISO-8859-1”%>

Insert title here

Post form

text:

I´m running this code on a JSP (JavaServerPage) in Eclipse and i get this message in return:

pðInvalid TCP frame received. Error: Package size is out of bounds: 1414745936 (max: 67108864)…

Can anyone help me to set the package size in event store or maybe the HTTP POST size to solve this problem?

1113 is the default tcp protocol port 2113 is the default http port :slight_smile:

My guess is you are posting to the protobuf/tcp server.

Greg

I also get this message in the cmd where I´m running the event store:

[03808,21,20:04:02.674] Connection ‘external-normal’ [127.0.0.1:9377, {de48987b-
bd4f-4a27-b315-87c3836f2636}] closed: Success.
[03808,24,20:07:07.871] External TCP connection accepted: [Normal, 127.0.0.1:941
7, L127.0.0.1:1113, {9377dc71-eb19-4bda-a6d4-b6d3cdd02fdb}].
[03808,23,20:07:07.871] External TCP connection accepted: [Normal, 127.0.0.1:941
8, L127.0.0.1:1113, {ab4aa582-ea3a-4792-9398-4bdc3392dcd3}].
[03808,24,20:07:07.871] FRAMING ERROR! Data:
000000: 50 4F 53 54 20 2F 20 48 54 54 50 2F 31 2E 31 0D | POST / HTTP/1.1.
000016: 0A 41 63 63 65 70 74 3A 20 69 6D 61 67 65 2F 6A | .Accept: image/j
000032: 70 65 67 2C 20 61 70 70 6C 69 63 61 74 69 6F 6E | peg, application
000048: 2F 78 2D 6D 73 2D 61 70 70 6C 69 63 61 74 69 6F | /x-ms-applicatio
000064: 6E 2C 20 69 6D 61 67 65 2F 67 69 66 2C 20 61 70 | n, image/gif, ap
000080: 70 6C 69 63 61 74 69 6F 6E 2F 78 61 6D 6C 2B 78 | plication/xaml+x
000096: 6D 6C 2C 20 69 6D 61 67 65 2F 70 6A 70 65 67 2C | ml, image/pjpeg,
000112: 20 61 70 70 6C 69 63 61 74 69 6F 6E 2F 78 2D 6D | application/x-m
000128: 73 2D 78 62 61 70 2C 20 2A 2F 2A 0D 0A 52 65 66 | s-xbap, /…Ref
000144: 65 72 65 72 3A 20 68 74 74 70 3A 2F 2F 6C 6F 63 | erer: http://loc
000160: 61 6C 68 6F 73 74 3A 38 30 38 31 2F 48 65 6D 73 | alhost:8081/Hems
000176: 69 64 61 6E 2F 53 69 64 61 36 2E 6A 73 70 0D 0A | idan/Sida6.jsp…
000192: 41 63 63 65 70 74 2D 4C 61 6E 67 75 61 67 65 3A | Accept-Language:
000208: 20 73 76 2D 53 45 2C 73 76 3B 71 3D 30 2E 38 2C | sv-SE,sv;q=0.8,
000224: 65 6E 2D 55 53 3B 71 3D 30 2E 35 2C 65 6E 3B 71 | en-US;q=0.5,en;q
000240: 3D 30 2E 33 0D 0A 55 73 65 72 2D 41 67 65 6E 74 | =0.3…User-Agent
000256: 3A 20 4D 6F 7A 69 6C 6C 61 2F 35 2E 30 20 28 63 | : Mozilla/5.0 (c
000272: 6F 6D 70 61 74 69 62 6C 65 3B 20 4D 53 49 45 20 | ompatible; MSIE
000288: 39 2E 30 3B 20 57 69 6E 64 6F 77 73 20 4E 54 20 | 9.0; Windows NT
000304: 36 2E 33 3B 20 57 69 6E 36 34 3B 20 78 36 34 3B | 6.3; Win64; x64;
000320: 20 54 72 69 64 65 6E 74 2F 37 2E 30 29 0D 0A 43 | Trident/7.0)…C
000336: 6F 6E 74 65 6E 74 2D 54 79 70 65 3A 20 61 70 70 | ontent-Type: app
000352: 6C 69 63 61 74 69 6F 6E 2F 78 2D 77 77 77 2D 66 | lication/x-www-f
000368: 6F 72 6D 2D 75 72 6C 65 6E 63 6F 64 65 64 0D 0A | orm-urlencoded…
000384: 55 41 2D 43 50 55 3A 20 41 4D 44 36 34 0D 0A 41 | UA-CPU: AMD64…A
000400: 63 63 65 70 74 2D 45 6E 63 6F 64 69 6E 67 3A 20 | ccept-Encoding:
000416: 67 7A 69 70 2C 20 64 65 66 6C 61 74 65 0D 0A 48 | gzip, deflate…H
000432: 6F 73 74 3A 20 31 32 37 2E 30 2E 30 2E 31 3A 31 | ost: 127.0.0.1:1
000448: 31 31 33 0D 0A 43 6F 6E 74 65 6E 74 2D 4C 65 6E | 113…Content-Len
000464: 67 74 68 3A 20 35 0D 0A 43 6F 6E 6E 65 63 74 69 | gth: 5…Connecti
000480: 6F 6E 3A 20 4B 65 65 70 2D 41 6C 69 76 65 0D 0A | on: Keep-Alive…
000496: 43 61 63 68 65 2D 43 6F 6E 74 72 6F 6C 3A 20 6E | Cache-Control: n
000512: 6F 2D 63 61 63 68 65 0D 0A 0D 0A 6E 61 6D 65 3D | o-cache…name=

[03808,24,20:07:07.872] Closing connection ‘external-normal’ [127.0.0.1:9417, L1
27.0.0.1:1113, {9377dc71-eb19-4bda-a6d4-b6d3cdd02fdb}] due to error. Reason: Inv
alid TCP frame received. Error: Package size is out of bounds: 1414745936 (max:
67108864)…
[03808,24,20:07:07.872] [20:07:07.872: N127.0.0.1:9417, L127.0.0.1:1113, {9377dc
71-eb19-4bda-a6d4-b6d3cdd02fdb}]:
Received bytes: 528, Sent bytes: 116
Send calls: 1, callbacks: 1
Receive calls: 2, callbacks: 1
Close reason: [Success] Invalid TCP frame received. Error: Package size is out o
f bounds: 1414745936 (max: 67108864)…

[03808,24,20:07:07.872] Connection ‘external-normal’ [127.0.0.1:9417, {9377dc71-
eb19-4bda-a6d4-b6d3cdd02fdb}] closed: Success.
[03808,14,20:07:15.873] Closing connection ‘external-normal’ [127.0.0.1:9418, L1
27.0.0.1:1113, {ab4aa582-ea3a-4792-9398-4bdc3392dcd3}] cleanly. Reason: HEARTBEA
T TIMEOUT at msgNum 0
[03808,14,20:07:15.873] [20:07:15.873: N127.0.0.1:9418, L127.0.0.1:1113, {ab4aa5
82-ea3a-4792-9398-4bdc3392dcd3}]:
Received bytes: 0, Sent bytes: 22
Send calls: 1, callbacks: 1
Receive calls: 1, callbacks: 0
Close reason: [Success] HEARTBEAT TIMEOUT at msgNum 0

[03808,14,20:07:15.873] Connection ‘external-normal’ [127.0.0.1:9418, {ab4aa582-
ea3a-4792-9398-4bdc3392dcd3}] closed: Success.

This is normal when you send http posts to the tcp protocol port. We attempt to reassemble frames of the messages and dont understand the frames as they are http not protobufs.

Okay thanks.
I´m trying to send a HTTP POST to event store, so the event store can make this POST to an event.
Is this possible to do if I´m using port 2113? When I´m trying to use port 2113, i get this message:
**Page can not be displayed on the site

HTTP 405

Most probable cause:
• There is a programming error on the site.

Try the following:

Return to the previous page.

More information**

Or should I use protobufs?
If that´s case, can you give me any advise with protobufs :)?

What url are you POSTing to?

So a 405 is not most likely a programming error on the site (maybe from a browser perspective yes). What you are receiving is a 405 method not allowed http://www.checkupdown.com/status/E405_en.html can you send the exact uri that you are posting to?

I ´m doing a HTTP POST to: http://127.0.0.1:2113
As I said, I´m using this HTML-code for the HTTP POST:
<%@ page language=“java” contentType=“text/html; charset=ISO-8859-1”
pageEncoding=“ISO-8859-1”%>

Insert title here **

Post form

text: **

Check out the required media types - thats not going to work.

Okay when you say required media types, do you mean json? Can you give me any examplecode that works or any advise?

Actually, that is also the wrong uri :slight_smile: You can’t POST to http://127.0.0.1:2113/. Try http://127.0.0.1:2113/streams/stream-id

Please see https://github.com/EventStore/EventStore/wiki/Writing-to-a-Stream-(HTTP) for more

It didn’t work to post to: http://localhost:2113/streams/Test/0

Can’t I create an eventstream with events from a simple POST or do I have to do it like this way but in HTML-code with data from a specific txt-file:

ouro@ouroboros:~$ curl -i -d@/home/greg/my:2113/streams/newstream -H "Content-Type:application/json" -H "ES-EventType: SomeEvent" -H "ES-EventId: C322E299-CB73-4B47-97C5-5054F920746E"

If that´s the case, can anyone give me any good example of HTML or PHP code for this?

You don’t post to an index of a stream You post to the stream. http://localhost:2113/streams/Test

Hi,

As far as I know you can’t do it directly from HTML - it would require JavaScript or similar to meet the media type requirements. I’m not personally familiar with PHP, but other people on this list are.

As Joao says, you need to post to the stream resource directly, not to an indexer:
http://localhost:2113/streams/Test

Cheers,

James

Okay thanks a lot for the help!

are you on 3.0? is it binaries or built from source as the doc states that includes very recent changes

Hi,

I have this Java HTTP code that is connected to Event Store and working fine.

Now I’m trying to translate this Java HTTP code to HTTP POST PHP code.

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.io.InputStreamReader;

import org.apache.http.HttpResponse;

import org.apache.http.client.ClientProtocolException;

import org.apache.http.client.HttpClient;

import org.apache.http.client.methods.HttpPost;

import org.apache.http.entity.StringEntity;

import org.apache.http.impl.client.DefaultHttpClient;

import org.apache.http.params.HttpParams;

import org.json.JSONArray;

import org.json.JSONException;

import org.json.JSONObject;

import org.json.JSONString;

import org.json.simple.parser.JSONParser;

import org.json.simple.parser.ParseException;

public class TestPost {

public static void main(String[] args) throws ClientProtocolException, IOException, JSONException, ParseException {

HttpClient client = new DefaultHttpClient();

HttpPost post = new HttpPost(“http://127.0.0.1:2113/streams/newstreamarna”);

post.addHeader(“content-type”, “application/json”);

// post.addHeader(“ES-EventType”, “SomeEvent”);

JSONObject jo = new JSONObject();

jo.put(“eventId”, “fbf4a1a1-b4a3-4dfe-a01f-ec52c34e16e4”);

jo.put(“eventType”, “event-type”);

jo.put(“data”, “{ a : 2 }”);

jo.put(“metadata”, “{ a : 1 }”);

JSONArray ja = new JSONArray();

ja.put(jo);

StringEntity input = new StringEntity(ja.toString());

post.setEntity(input);

HttpResponse response = client.execute(post);

BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

String line = “”;

while ((line = rd.readLine()) != null) {

System.out.println(line);

}

}

}

I have tried to use this PHP code:

$url = 'http://127.0.0.1:2113/streams/newstreamarna';
$data = array('key1' => 'value1', 'key2' => 'value2');

// use key 'http' even if you send the request to https://...
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data),
    ),
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);

var_dump($result);

But when I use this PHP code i get an error on the HTML site, the code is shown on the HTML site, see picture.

It doesn’t work, what do I do wrong? Is the code on the wrong place? Can you give me any advice if there is a easier way to do HTTP POST PHP that can connect to Event Store?

Here is the full HTML code:

Din Mat

Din Mat

Startsida

Kryssa i en av varje kategori

Måltid

Frukost

Lunch

Middag

Mellanmål

Dessert

Ursprung

Afrika

Asien

Europa

Nordamerika

Sydamerika

Tid

15 min

30 min

60 min

120 min

120+ min










<?php if (isset($_GET['todo'])) { $maltidid = $_GET['maltidid']; $ursprungid= $_GET['ursprungid']; $tidid= $_GET['tidid']; $dbhost = 'localhost'; $dbuser = '***'*; $dbpass = '****'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $sql = 'SELECT beskriv FROM recept WHERE maltidid='.$maltidid.' AND ursprungid='.$ursprungid.' AND tidid='.$tidid; mysql_select_db('m11p0753'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not get data: ' . mysql_error()); } while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) { echo ""; $sEncoding = mb_detect_encoding($row['beskriv']); $str = mb_convert_encoding($row['beskriv'], 'Windows-1252', 'UTF-8'); echo $str; echo "
"; } mysql_close($conn); $url = 'http://127.0.0.1:2113/streams/newstreamarna'; $data = array('key1' => 'value1', 'key2' => 'value2'); // use key 'http' even if you send the request to https://... $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data), ), ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); var_dump($result); } ?>

Copyright (c) 2014 by Din Mat

Thankful for any help I get, Cheers!

bild1.png

The java code is posting json and you are posting


"Content-type: application/x-www-form-urlencoded\r\n"


That is a fairly big difference! Try as json

Hi,

You mean something like this? Is there any easier way to do HTTP POST PHP?

‘Content-type’ => ‘application/vnd.eventstore.events+json’

Well and post the data as json not as url-encoded data