I am using this below code to add a product to the cart from a phtml file:
<form data-role="tocart-form" action="<?php echo $addToCartUrl; ?>" method="post">
<?php echo $block->getBlockHtml('formkey')?>
<div class="btn">
<button type="submit" title="Add to Cart" class="action tocart primary">
<span>Add to Cart</span>
</button>
</div>
</form>
But at $addToCartUrl, I receive some extra characters like this:
www.webi.com/checkout/cart/add/uenc/aHR0cHM6Ly93d3cudGliby50di8yMDE4OS9ibGk%2C/product/2/
The part before /product/2/ adds these characters: %2C
and in this way, I can't add the product to cart!