html複雜url提交

來源:互聯網
上載者:User

標籤:

在使用手機向webapi發送照片請求的時候遇到一個問題,關於base64位字串碼無法識別,提交的表單是這樣的:

<form id="form1" method="post" action="http://localhost:10322/food/Buy?date=‘2015-2-12‘&content=balabala內容"><div><input type="text" name="PhotoInfo" value="base位碼"/><input type="submit" value="提交" /></div></form>

由於PhotoInfo特別長,不能放在url拼接,會報異常,所以放在form裡面提交,但是api端卻捕捉不到,產生url異常.

解決方案:在對應的buy方法的PhotoInfo參數前面加上[Frombody]標記

public ResponseMessage Buy(string date,string content,[FromBody] string PhotoInfo)

加上這個標記後,webapi端能找到了,但是又有問題出現了,photoInfo明明有值,傳進來卻是null,查了一下,預設string類型不會傳值,必須用自訂類型,好吧,定義個自訂類型

public class Photo {        public string Extension { get; set; }        public string PhotoImage { get; set; }    }

然後在參數使用的地方改成

public ResponseMessage Buy(string date,string content,[FromBody] Photo PhotoInfo)

取值的地時候要用PhotoInfo.PhotoImage,這時候就有值了,另外,在傳base64位碼的時候,前面的data:image/gif;base64, 這個不能加上,加上識別不了。

 

html複雜url提交

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.