No, what I need to do is find a way prevent SWI Prolog from automatically converting my non-multipart requests into multipart requests (It seems to be doing this weird behaviour in order to create non-existent cookies)
My workaround (that works) shows what I am trying to do is this simple:
get_post_reply(_Host,URL, PostData, Reply):-
atom_length(PostData,Len),
tcp_socket(Socket),
tcp_connect(Socket, 'localhost':4090),
tcp_open_socket(Socket, Read, Write),
sformat(S,"POST ~w HTTP/1.0\r
From: logicmoo@gmail.com\r
User-Agent: Raw-Socket/1.0\r
Content-Type: application/x-www-form-urlencoded\r
Content-Length: ~d\n\n~w\n",[URL,Len,PostData]),
format(Write,"~s",[S]), flush_output(Write),catch(close(Write),_,true),
% format(user_error,"~N`~s`~N",[S]), flush_output(user_error),
peek_code(Read,C),
( [A123] = `{` ),
my_stream_to_codes(A123,C,Read,_,[]),
my_stream_to_codes(-1,A123,Read,Codes,[]),
%format(user_error,"~N~s~N",[Codes]), flush_output(user_error),
catch(close(Read),_,true),
open_codes_stream(Codes,Stream),
json:json_read(Stream,Reply),
close(Stream),
!.
my_stream_to_codes(_,-1, _Stream, Tail, Tail) :- !.
my_stream_to_codes(EOC,EOC, _Stream, Tail, Tail) :- !.
my_stream_to_codes(EOC,C, Read, [C|T], Tail) :-
% format(user_error,"~s",[[C]]), flush_output(user_error),
get_code(Read,C),
peek_code(Read,C2),
my_stream_to_codes(EOC,C2, Read, T, Tail).
( logicmoo_workspace/parser_stanford.pl at 895fd4c26ad6ea977d01cd9f89eaf4ca7a5d93ba · logicmoo/logicmoo_workspace · GitHub )
Ideally it would be better to use the http library to achieve this! Such as http_post/4
should be capable of doing what I am doing above?
get_post_reply(HOST,URL, PostData, Reply):-
atom_concat(HOST,URL,PARAMS),
http_post(PARAMS, [PostData], json(Reply), []).