AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
DAX
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 11.11.2013, 11:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
workflowax: JSON in Dynamics AX – Advanced example #1 (Basic Auth)
Источник: http://workflowax.wordpress.com/2013...-1-basic-auth/
==============

After my previous post on using JSON in Dynamics AX2012 I have received a number of requests for some slightly more advanced examples. I will attempt over the next couple of weeks to provide some.

Today I will cover the use of Basic http authentication. There are a couple of non-intuitive tricks that one needs to use to get it to work.
Before performing any direct requests as per our previous example you will need to make some modifications to the headers in your RetailRequestWeb object.

The first header modification is to add the “Authorization: Basic ” header. You can do so by building up the header string as follows

System.Text.Encoding ascii;str credentials;credentials = "myusername:mypassword";//N.B. Encode the credentials before adding them to your headers otherwise you will receive 403 unauthorized errorsascii = System.Text.Encoding::get_ASCII();credentials = System.Convert::ToBase64String(ascii.GetBytes(credentials));//Combine header instruction and encoded credentialsrequest.parmHeader("Authorization: Basic "+credentials);The second modification you need to make is set the request content type to “application/json” without this you may receive 403 unauthorized errors. The retails API allows you to set the content type easily by using the parmContentType method on your RetailRequestWeb object.

request.parmContentType("application/json");Finally the full example of constructing your json request ready for use:

RetailWebRequest request;System.Text.Encoding ascii;str credentials;request = RetailWebRequest::newUrl(_url);credentials = "myusername:mypassword";ascii = System.Text.Encoding::get_ASCII();credentials = System.Convert::ToBase64String(ascii.GetBytes(credentials));request.parmHeader("Authorization: Basic "+credentials);request.parmContentType("application/json");


Источник: http://workflowax.wordpress.com/2013...-1-basic-auth/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Теги
json

 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
workflowax: Using JSON in Dynamics AX Blog bot DAX Blogs 0 22.10.2013 19:12
atinkerersnotebook: Using Export To Excel in Dynamics AX to Create Reporting Data Sources Blog bot DAX Blogs 1 12.10.2013 01:13
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 12 Blog bot Dynamics CRM: Blogs 0 30.01.2013 01:11
Developer for Microsoft Dynamics AX Certification Roadmap Blog bot DAX Blogs 1 13.05.2009 16:17
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 23:12.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.