lukeclopez

lukeclopez

The approximate code:

    params = %{query: "https://www.lol.com"}
    params = Jason.encode!(params)
    HTTPoison.post(url, params, headers, @options)

The approximate request and response:

[
  {
    "request": {
      "body": "{\"query\":\"https://lol.com\"}",
      "url": "https://url.com",
      "headers": {
        "Authorization": "***",
        "Content-Type": "application/json"
      },
      "method": "post",
      "request_body": ""
    },
    "response": {
      "binary": false,
      "type": "ok",
      "body": "{\"message\":\"Bad Request\"}\n",
      "headers": {
        "content-type": "application/json",
        "content-length": "26"
      },
      "status_code": 400
    }
  }
]

Inspecting the body also returns "{\"query\":\"https://lol.com\"}"

As far as I can tell, it’s from the extra slash that comes after .com to escape the double quote.

What I’ve tried:
Building the body in a sigil like these:
~S({"query":"https://lol.com"})
~s<{"query":"https://lol.com"}>

Replacing the slash with String.replace

Using req instead of HTTPoison

This is a 3rd party API so I don’t have control over how their server receives it. Any further ideas for a client-side solution (the client being my Elixir code)?

I can get a curl request working with all the same params, but I can’t make it work in Elixir.

These seem to fail because Elixir always represents JSON object strings with escaped quotes.

curl 'https://url.com' 'Content-Type: application/json' -d '{\n "query": "https://lol.com"    }

Showing Posts 1 to 5

NobbZ

NobbZ

First difference I see is the UA.

So try setting a UA that is close to what curl does.

Hermanverschooten

Hermanverschooten

This is odd, because those are just representational.

If you would do File.write("test.txt", Jason.encode(%{query: "https://www.lol.com"}), you would see no backslashes.

If I take your example of above:

"{\"query\":\"https://lol.com\"}" |> String.length()
"{'query':'https://lol.com'}" |> String.length()
Both of these will return 27.

So I don’t think this is your issue.

NobbZ

NobbZ

PS: To make one thing clear, I do not see an “extra” slash (/) anywhere, only some backslash (\) which often is confusing.

Please make sure to understand that escaping it is a purely representational thing.

iex(1)> "{\"query\":\"https://lol.com\"}" == ~s<{"query":"https://lol.com"}>
true
axelson

axelson

Scenic Core Team

Can you show the full curl command that works?

lukeclopez

lukeclopez OP

Thank you everyone for your patience and your responses.

The issue was not the backslash (which I incorrectly called a slash) as you pointed out. The issue was that this request required Basic Auth, which evidently must be Base64 encoded in order to work. I was sending the auth string in plaintext.

Problem solved. Thank you!

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews