POST in RESTful web service - web-services

am trying to learn the basic CURD operations to do in RESTful web service using Jersy or Restlet.
Could anyone provide me with some examples on how to POST a word/message from ONE web application to another web application (i.e) to POST a message from the first application and then to implement GET in the second application to receive it.
Thanks,

may it's useful for you its codeigniter post web service demo
public function add_category() {
############### post parameter #######
$user_id = $this->is_require($_POST, 'user_id');
$user_token = $this->is_require($_POST, 'user_token');
$cat_name = $this->is_require($_POST, 'cat_name');
$parent_id = $this->is_require($_POST, 'parent_id');
$this->Is_authorised($user_id, $user_token, 1);
#######################################
$q = "select * from tbl_category where cat_name='$cat_name' and parent_id ='$parent_id' limit 1";
$c_exits = $this->basic->select_custom($q);
if (!empty($c_exits)) {
$this->msg = "category already exist";
$this->_sendResponse(2);
}
$inn = array(
'cat_name' => $cat_name,
'parent_id' => $parent_id,
);
$temp = $this->basic->insert_entry("tbl_category", $inn, TRUE);
if ($temp['stat'] == 1) {
$this->result['cat_id'] = $temp['last_id'];
} else {
$this->_sendResponse(0);
}
$this->_sendResponse(1);
}

Related

POST failed via Postman API to Laravel migrations database

GET is working, but POST does not. This is because it fails via Postman API to the Laravel migrations database.
function add_user(Request $request)
{
$user = new user_a;
csrf_token();
$user->user_name = $request->user_name;
$user->password = $request->password;
$res = $user->save;
if ($res) {
return ["operationn" => "Done"];
} else {
return ["operation" => "failed_404"];
}
}
in API file:
Route::post('registeruser',[dynamic_small_controller::class,'add_user']);
You are trying to send the password in integer format so it is not accepting try with giving password also in ""
{
"user_name":"yahay",
"password":"8888"
}

Getting .NET Core, WS Federation, Identity Core Issue with TicketDataFormat

I have two applications that are using WS Federation and I am working to migrate one of these applications over to .NET Core. These two applications need to be able to share cookies and this is where I am running into an issue on the .NET Core side.
This is a portion of my Startup.cs
services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<Context>()
.AddDefaultTokenProviders();
services.ConfigureApplicationCookie(options =>
{
options.LoginPath = new PathString("/Account/Login");
//LOGIN WORKS CORRECTLY WITH THE BELOW LINE COMMENTED
options.TicketDataFormat = new AuthTicketDataFormat();
options.Cookie.Name = "cookiename";
options.Cookie.Path = "/";
options.Cookie.Domain = "";
});
services.ConfigureExternalCookie(options => {
options.LoginPath = new PathString("/Account/Login");
//LOGIN WORKS CORRECTLY WITH THE BELOW LINE COMMENTED
options.TicketDataFormat = new AuthTicketDataFormat();
options.Cookie.Name = "cookiename";
options.Cookie.Path = "/";
options.Cookie.Domain = "";
});
services.AddAuthentication()
.AddWsFederation(options => {
// MetadataAddress represents the Active Directory instance used to authenticate users.
options.MetadataAddress = authentication.GetValue<string>("AdfsWsFedMetadataUri");
// Wtrealm is the app's identifier in the Active Directory instance.
// For ADFS, use the relying party's identifier, its WS-Federation Passive protocol URL:
options.Wtrealm = authentication.GetValue<string>("AdfsRelyingPartyIdentifier");
});
I am able to see that I do receive a cookie in the Network tab, but the issue I am having is that I am being put into an infinite loop because on my anonymous Callback endpoint I have the following:
var loginInfo = await this._signInManager.GetExternalLoginInfoAsync();
//loginInfo is always coming back as null
if (loginInfo == null) {
return RedirectToAction("Login");
}
It seems the issue is being caused by options.TicketDataFormat and creating a custom format for the cookie. The cookie seems to be created correctly with the ticketDataFormat, but getExternalLoginInfoAsync on signInManager is always returning null.
Any help or direction is greatly appreciated as I've been banging my head against the wall for a day trying to figure this out.

how to call synchronous web service call in xamarin forms?

I am creating an application in xamarin forms which needs synchronous web service call. But only GetAsync is available in xamarin forms. can anyone please explain me how to call synchronous web service call in xamarin forms?
Try something like this
public Webservice() { }
public Home GetHome()
{
string strpost = "";
var client = new System.Net.Http.HttpClient();
client.BaseAddress = new Uri(" xyz ");
var response = client.PostAsync(new Uri(" xyz "), str).Result;
var result = JsonConvert.DeserializeObject<Home>(response.Content.ReadAsStringAsync().Result);
Home home = new Home();
if (!Equals(result, null))
{
home = result;
return home;
}
}
Refer: https://forums.xamarin.com/discussion/43397/how-to-call-synchronous-webservice

TermSet Creation gives error in SharePoint 2013 using custom webservice

I am trying to create a new term set in SharePoint 2013 using a custom WCF web service deployed within SharePoint 2013 server. I have written below code to create the term set.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (Impersonator imp = new Impersonator("Username", "Domain", "Password"))
{
using (SPSite site = new SPSite("http://server:8002/sites/site/"))
{
site.AllowUnsafeUpdates = true;
TaxonomySession session = new TaxonomySession(site);
TermStore termStore = session.TermStores["Managed Metadata Service"];
var termStoreAdmin = termStore.TermStoreAdministrators.Where(obj => obj.PrincipalName.Contains("domain\\username")).FirstOrDefault();
if (termStoreAdmin == null)
termStore.AddTermStoreAdministrator("domain\\username");
Group group = termStore.GetGroup(new Guid(groupGuid));
if (group != null && !string.IsNullOrEmpty(termSetName))
{
TermSet termset = group.TermSets.FirstOrDefault(obj => obj.Name.Equals(termSetName));
if (termset == null)
{
termset = group.CreateTermSet(termSetName);
termSetGuid = termset.Id.ToString();
}
SetupNavTermSet(termset, session, site.OpenWeb());
}
termStore.CommitAll();
}
}
});
I am calling this method from silverlight code using soap message. While calling this code I am getting exception while executing group.CreateTermSet(termSetName); line.
The error is:
Error Message : Value cannot be null.
Source : Microsoft.SharePoint
Error Details : at Microsoft.SharePoint.Administration.Claims.SPClaimProviderManager.GetUserIdentifierEncodedClaim(IIdentity identity)
at Microsoft.SharePoint.Taxonomy.Internal.CommonUtilities.GetCurrentUserName()
at Microsoft.SharePoint.Taxonomy.TaxonomySession.get_CurrentUserName()
at Microsoft.SharePoint.Taxonomy.Group.CreateTermSet(String name, Guid newTermSetId, Int32 lcid)
at Microsoft.SharePoint.Taxonomy.Group.CreateTermSet(String name)
at SplitVisionMetadataManagement.CustomManageMetaDataWCFService.<>c__DisplayClassc.<CreateTaxonomyTermSet>b__8()
Has anybody got this issue and a solution?
I also encountered the same issue and figured out that the Microsoft.SharePoint.Taxonomy.Internal.CommonUtilities.GetCurrentUserName() method uses the HttpContext.Current.User security principal for arriving at the user name.
I am using similar code in a windows form application and hence the HttpContext was empty. I made a workaround by setting the context and user manually as below.
if (HttpContext.Current == null)
{
HttpRequest request = new HttpRequest("", SiteURL, "");
HttpContext.Current = new HttpContext(request, new HttpResponse(TextWriter.Null));
HttpContext.Current.User = System.Threading.Thread.CurrentPrincipal;
}
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SiteURL))
{
using (SPWeb web = site.OpenWeb())
{
if (HttpContext.Current.Items["HttpHandlerSPWeb"] == null)
HttpContext.Current.Items["HttpHandlerSPWeb"] = web;
// Your SharePoint Term Creation code
}
}
});
In your case it seems like you are using claims based authentication and hence some issue with the claims provider in returning the name. You HTTP context would be the context under which the WCF is running. You may need to investigate further in those angle.
The above knowledge should help you to understand it further.

client send json and retrieve it in server

Now I'm bulding game by UNITY3D. I want to send json file to server to store it in database I build server by php with Yii Framework, i have problem with send data in client [UNITY3D] and retrieve it in server [Yii]. Please help me.UNITY3D code: I want to send 'name' -> to server
var url = "http://localhost:8888/TPP/index.php/site/saveName";
var form = new WWWForm();
form.AddField( "player", "Henry" );
var download = new WWW( url, form );
print(download);
yield download;
if(download.error) {
print( "Error downloading: " + download.error );
return;
} else {
// show the highscores
Debug.Log(download.text);
}
In Yii, i tried to get data in request
public function actionSaveName() {
if(isset($_POST['name']) {
echo $_POST['name'];
} else {
echo "nothing";
}
}
Is that right?
The unity part is fine, but in yii you'll have to check for $_POST['player'] instead of $_POST['name'] because according to the AddField() documentation, the first parameter is the name of the generated form element.
If you want to have it as name then you'll have to change AddField as : form.AddField("name", "Henry");